topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • Saturday December 14, 2024, 8:25 am
  • Proudly celebrating 15+ years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Last post Author Topic: last window id  (Read 35903 times)

cardboard42

  • Participant
  • Joined in 2008
  • *
  • Posts: 4
    • View Profile
    • Donate to Member
last window id
« on: March 07, 2009, 12:02 PM »
Is it possible to get the hwnd of the last focused window in a plugin or alias? I know farr tracks it for other features, but it would be really helpful to be able to use it for other things. If it's not currently possible, consider this a feature request.

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 40,914
    • View Profile
    • Mouser's Software Zone on DonationCoder.com
    • Read more about this member.
    • Donate to Member
Re: last window id
« Reply #1 on: March 07, 2009, 12:07 PM »
Hi cardboard:

%LASTHWND% - integer value referring to the last window handle that had focus before FARR was triggered.

FARR actually uses such information when doing it's pasting functions, so that it can paste into the program that had focus when it was triggered.

Happy to answer more questions if you have an idea you are trying to implement.
« Last Edit: March 07, 2009, 12:09 PM by mouser »

cardboard42

  • Participant
  • Joined in 2008
  • *
  • Posts: 4
    • View Profile
    • Donate to Member
Re: last window id
« Reply #2 on: March 07, 2009, 12:49 PM »
Basically I'm trying to implement a FARR version of the AHK Favorite Folders script (which I was the original author of). I'm now trying to make an alias action keyword that would launch a ahk script with the last hwnd and the selected result. This script would navigate the last focused window appropriately. Unfortunately I can't get the keyword to work.

I defined the alias like this: 1000>>>+test>#>C:\Command\Shell\AutoHotkey\Scripts\wintest.ahk %LASTHWND% "$$1"
And tried to use it like this: +test C:\command
I expected it to launch my script with C:\command as the second arg, but it just does the usual action.
Am I missing something here?

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 40,914
    • View Profile
    • Mouser's Software Zone on DonationCoder.com
    • Read more about this member.
    • Donate to Member
Re: last window id
« Reply #3 on: March 07, 2009, 01:15 PM »
i need to understand a little bit more about what you want to do.

IF what you want to do is type something like:
cardboardtest WHATEVERIWANT

and have it launch
C:\Command\Shell\AutoHotkey\Scripts\wintest.ahk %LASTHWND% "WHATEVERIWANT"

then what you want is just to define an alias and specify the regular expression
^cardboardtest (.*)$

that will capture the $$1 as you intend.



however if what you want is to let user search for a file the normal way, and use that found file as the $$1 then it's a little bit more complicated and you are on the right path.  i think the problem is you dont put the + in your alias name when you define the alias. just use test or cardboardtest whatever.

the + is the way the user tells FARR when they are typing that they want to use the alias to launch the result.

cardboard42

  • Participant
  • Joined in 2008
  • *
  • Posts: 4
    • View Profile
    • Donate to Member
Re: last window id
« Reply #4 on: March 07, 2009, 01:29 PM »
Awesome, leaving off the plus did what I intended, though it seems that may not have been what I wanted  ;)
I'll have to experiment a bit to find the nicest method.
Thanks for your help!

rulfzid

  • Participant
  • Joined in 2008
  • *
  • Posts: 28
    • View Profile
    • Donate to Member
Re: last window id
« Reply #5 on: March 17, 2009, 02:57 AM »
I hope I'm not stepping on any toes, but I had already come up with a solution, borrowing heavily from the Favorite Folders AHK script (which so many have come to know and love). I basically ripped off the meat of the script and passed it a couple of command-line arguments from FARR. I also tweaked it a tiny bit so that it works in Vista and 7.

You'll find 4 files in the zipped up alias pack:
  • FarrFolders.ahk
  • FarrFolders.alias
  • FarrFolders.exe
  • FarrFolders.ico

The AHK script is there in case anybody would like to tweak anything/view source. The alias itself uses the exe for ease of passing command-line parameters.

Basically, unzip the files into your AliasGroups/MyCustom folder. The alias itself is set to "faf", because i find that quick and easy to type and because "ff" kept showing "Microsoft Office" results for me.

Type "faf" into FARR, and you should see the three example folders. If the last window open is an explorer window, command console, or open file dialog, the script will navigate you to the selected folder in that window. If not, it will open a new explorer window.

To add more folders, simply edit the alias from within FARR (or directly in the FarrFolders.alias file). You'll see 3 examples already included:
  • Desktop | %ALIASDIR%\FarrFolders.exe %LASTHWND% %MYDESKTOP%
  • Program Files | %ALIASDIR%\FarrFolders.exe %LASTHWND% %PROGRAMFILES%
  • My Documents| %ALIASDIR%\FarrFolders.exe %LASTHWND% %MYDOCUMENTS%

As you can see, these take the form of:

<folder_name> | %ALIASDIR%\FarrFolders.exe %LASTHWND% <folder_path>

where <folder_name> is the name of the folder as you'd like it to appear in your results and <folder_path> is the full path to the folder, which can (and should) utilize the FARR virtual folder names as much as possible. Leave the rest of the line the same, obv.

mouser, I was thinking about creating a "faf" alias command to edit the list, but it seems as though if I edit the alias file externally, the list doesn't automatically update the next time I type the alias. I could get it to do so if I manually opened up the "edit alias" box and closed it again, but not otherwise. Is there a way to get it to automatically rescan the alias file and refresh the results list? I'd like to add this functionality.

Till then, enjoy! This alias has already become indispensable to me - I hope it proves useful to others.

nitrix-ud

  • Charter Member
  • Joined in 2005
  • ***
  • default avatar
  • Posts: 560
    • View Profile
    • Donate to Member
Re: last window id
« Reply #6 on: March 17, 2009, 03:24 AM »
mouser, I was thinking about creating a "faf" alias command to edit the list, but it seems as though if I edit the alias file externally, the list doesn't automatically update the next time I type the alias. I could get it to do so if I manually opened up the "edit alias" box and closed it again, but not otherwise. Is there a way to get it to automatically rescan the alias file and refresh the results list? I'd like to add this functionality.

try the #filecontents command ;)

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 40,914
    • View Profile
    • Mouser's Software Zone on DonationCoder.com
    • Read more about this member.
    • Donate to Member
Re: last window id
« Reply #7 on: March 17, 2009, 03:32 AM »
holy hell it works. that is VERY cool.
now you only need one more element to make this super useful, which is simply to let the user use this alias to activate with ANY folder shown in farr window in this way.  and this is pretty easy to do, let me add it.

couple things you could do in your farrfolders.exe that might help:
if folder passed ends in \ then remove it
if a filename is passed to farr folders, it actually worked for me but triggered an automatic Enter in my file open dialog.

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 40,914
    • View Profile
    • Mouser's Software Zone on DonationCoder.com
    • Read more about this member.
    • Donate to Member
Re: last window id
« Reply #8 on: March 17, 2009, 03:36 AM »
here's an additional alias that does what i was suggesting.

so for example, if you have the file open dialog of any program open, now you can bring up far, then search for the folder or file you want, or use directory browsing in farr, and type +fao at the end of your search string and trigger the result -- it will change to that folder or file thanks to the amazing farrfolders.

or type "fao explicit path here" to go to specific folder (but it wont search as you type, for that you need to put +fao)

Screenshot - 3_17_2009 , 3_33_18 AM.png

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 40,914
    • View Profile
    • Mouser's Software Zone on DonationCoder.com
    • Read more about this member.
    • Donate to Member
Re: last window id
« Reply #9 on: March 17, 2009, 03:45 AM »
it would be more useful probably to be able to type it at start of string, which could be done with another alias (really i should fix farr so that the +fao can go at begining or end or so that typeing "fao blah" showed a live search, ill add that).

when you combine that with adding a special hotkey to farr to bring up farr with it preloaded with the +fao, what you have is a very very easy way to do live search in any program's file open/save dialog.

very cool.

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 40,914
    • View Profile
    • Mouser's Software Zone on DonationCoder.com
    • Read more about this member.
    • Donate to Member
Re: last window id
« Reply #10 on: March 17, 2009, 03:47 AM »
nitrix is right about the ideal way to handle your alias customization: https://www.donation...ex.php?topic=17270.0
another advantage of that is that to let use "edit" the list of known alias entries, you could just launch notepad with that text file containing alias contents.
« Last Edit: March 17, 2009, 03:56 AM by mouser »

rulfzid

  • Participant
  • Joined in 2008
  • *
  • Posts: 28
    • View Profile
    • Donate to Member
Re: last window id
« Reply #11 on: March 17, 2009, 12:50 PM »
Awesome, I didn't know about #filecontents, and it's exactly what I needed. I can now implement some of the fun bells and whistles that I wasn't quite sure I was going to be able to do.

I have another question, concerning your creation of another alias. If the regex for 'faf' were modified to "faf (.*)", does that mean that if I type "faf <somecommand>" that it will still launch the first result when I hit enter?

Basically, I'm thinking about adding some commands to faf and then just having the FarrFolders script parse the commands. Just trying to figure out the best way to do that.

skajfes

  • Honorary Member
  • Joined in 2008
  • **
  • Posts: 267
    • View Profile
    • Donate to Member
Re: last window id
« Reply #12 on: March 17, 2009, 06:51 PM »
Wow, great idea. I think I am gonna love this extension, thanks.

I've tweaked it a bit to support Directory Opus and Office 2007 dialogs.
It is impossible to make anything foolproof because fools are so ingenious.

rulfzid

  • Participant
  • Joined in 2008
  • *
  • Posts: 28
    • View Profile
    • Donate to Member
Re: last window id
« Reply #13 on: March 17, 2009, 06:59 PM »
Wow, great idea. I think I am gonna love this extension, thanks.

I've tweaked it a bit to support Directory Opus and Office 2007 dialogs.

Awesome! I'll be sure to include your changes as I do more stuff to/with this.


TucknDar

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 1,133
    • View Profile
    • Donate to Member
Re: last window id
« Reply #14 on: March 18, 2009, 06:46 AM »
Would be nice with user variable 'FileManager=[customfilemanager]' so it'll open a dir in a user's favourite file manager if no Open Dialog is... open. Even better would be if it could read FARR's setting for custom file explorer, but I don't know if that's possible.

Otherwise this could be on it's way to becoming a favourite (no pun intended) of mine!

rulfzid

  • Participant
  • Joined in 2008
  • *
  • Posts: 28
    • View Profile
    • Donate to Member
Re: last window id
« Reply #15 on: March 18, 2009, 12:53 PM »
Would be nice with user variable 'FileManager=[customfilemanager]' so it'll open a dir in a user's favourite file manager if no Open Dialog is... open. Even better would be if it could read FARR's setting for custom file explorer, but I don't know if that's possible.

Otherwise this could be on it's way to becoming a favourite (no pun intended) of mine!

Great idea. And it looks like FARR stores the custom file managers info in the FindAndRunRobot.ini file, so I could just read it from there. I'll update this pack soon.


mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 40,914
    • View Profile
    • Mouser's Software Zone on DonationCoder.com
    • Read more about this member.
    • Donate to Member
Re: last window id
« Reply #16 on: March 18, 2009, 02:07 PM »
i'm happy to make the custom file explorer available as a %variable% so you can pass it on commandline if you like.

rulfzid

  • Participant
  • Joined in 2008
  • *
  • Posts: 28
    • View Profile
    • Donate to Member
Re: last window id
« Reply #17 on: March 18, 2009, 04:19 PM »
i'm happy to make the custom file explorer available as a %variable% so you can pass it on commandline if you like.

That would be fantastic. :)

nitrix-ud

  • Charter Member
  • Joined in 2005
  • ***
  • default avatar
  • Posts: 560
    • View Profile
    • Donate to Member
Re: last window id
« Reply #18 on: March 18, 2009, 06:18 PM »
i'm happy to make the custom file explorer available as a %variable% so you can pass it on commandline if you like.

good idea ;)

please while you are at it, could you please add the %LASTURL% variable ;)  :P

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 40,914
    • View Profile
    • Mouser's Software Zone on DonationCoder.com
    • Read more about this member.
    • Donate to Member
Re: last window id
« Reply #19 on: March 18, 2009, 06:23 PM »
done and done.  will be in next update.

nitrix-ud

  • Charter Member
  • Joined in 2005
  • ***
  • default avatar
  • Posts: 560
    • View Profile
    • Donate to Member
Re: last window id
« Reply #20 on: March 18, 2009, 06:59 PM »
 :-*

ewemoa

  • Honorary Member
  • Joined in 2008
  • **
  • Posts: 2,922
    • View Profile
    • Donate to Member
Re: last window id
« Reply #21 on: March 18, 2009, 09:30 PM »
Excellent add-on  :Thmbsup:

BTW, I'm not finding root drives to work mostly (e.g. C: nor C:\) -- though it seems to work by accident(?) for cmd.exe.  Any one else experience this?

As far as specific situations where I had problems is concerned:

  • the save as dialog in notepad
  • working with windows explorer windows

rulfzid

  • Participant
  • Joined in 2008
  • *
  • Posts: 28
    • View Profile
    • Donate to Member
Re: last window id
« Reply #22 on: March 18, 2009, 09:57 PM »
Excellent add-on  :Thmbsup:

BTW, I'm not finding root drives to work mostly (e.g. C: nor C:\) -- though it seems to work by accident(?) for cmd.exe.  Any one else experience this?

As far as specific situations where I had problems is concerned:

  • the save as dialog in notepad
  • working with windows explorer windows

Which windows version are you on?

And part of that seems to be the trailing "\", which, as per mouser's suggestion above, I'm going to automatically remove.

I'll be posting an update soon - real busy with work, but I'm hoping to finish adding what I want to in the next day or two.

ewemoa

  • Honorary Member
  • Joined in 2008
  • **
  • Posts: 2,922
    • View Profile
    • Donate to Member
Re: last window id
« Reply #23 on: March 18, 2009, 10:06 PM »
I am using Windows XP Pro SP3 -- non-English though.

Thanks for your efforts  :Thmbsup:

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 40,914
    • View Profile
    • Mouser's Software Zone on DonationCoder.com
    • Read more about this member.
    • Donate to Member
Re: last window id
« Reply #24 on: March 18, 2009, 11:52 PM »
beta uploaded to https://www.donation...AndRunRobotSetup.exe
i'd appreciate some beta reports before i make it official.