Link to home
Start Free TrialLog in
Avatar of Luis Diaz
Luis DiazFlag for Colombia

asked on

Autohotkey: open file location

Hello Experts, ,
I am trying to set up a shortcut to open file location as reported bellow.
User generated imageWhen I launch manually the following keys it works Shift + F10 + down arrow+ enter
However when I send through ahk it doesn’t.
^F8::
Send, +{F10}
;~ Sleep, 5
;~ Send, {Down}{Enter}
Return

Open in new window

Any idea?
Thank you for your help.
Regards,
Luis.
Avatar of Joe Winograd
Joe Winograd
Flag of United States of America image

Hi Luis,
Before I jump into this one, where do things stand on the other open one:
https://www.experts-exchange.com/questions/29153254/Authotkey-send-keys-if-a-windows-explorer-is-active.html
Regards, Joe
Hi Luis,
Thanks for closing the other question. For this one, what program were you in when you hit Shift+F10? In other words, what program was active when you captured the screenshot that you posted? Regards, Joe
Avatar of Luis Diaz

ASKER

Joe, Excel was active. Should I planned to minimize all active windows to be able to launch shift+f10?
In W10, Shift+F10 displays the context menu for the selected item (same as a right-click on it). I asked the question because I was trying to figure out why that particular context menu appeared (I can't reproduce it here). Of course, it's possible that an application may hijack Shift+F10, such as our favorite AutoHotkey. :)

What exactly do you mean by "shortcut to open file location"? There may be a better way to do it in AutoHotkey, but I need to understand what you want. For example, do you want to open a specific file location in File Explorer? If so, what location? If not, what should be opened and what program should open it? Regards, Joe
Joe,
Everytime when I search a file I heat on win to make available search bar and type filaname. When I get a result displayed. I don't want to click on the file to avoid opening what I want is to open folder in which is located the file displayed.
ASKER CERTIFIED SOLUTION
Avatar of Joe Winograd
Joe Winograd
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Joe, unable to test it right now. I will do it tomorrow. Thank you.
Hi Luis,
I'll be here tomorrow. In the meantime, I did a very short video for you showing the AutoHotkey script working on my W10 machine:
luis-ctrl-f8.mp4
Regards, Joe

Update: Just discovered an issue, i.e., the number of down-arrows needed varies depending on the results of the search. For example, in the video, two are needed, because the first menu pick is "Run as administrator" and the second is "Open file location". But if, for example, you search for "cont" and then do a Shift+F10 on Control Panel, you need only one down-arrow, because the first menu pick is "Open file location". A common way to handle that in menus is to use the unique access key shortcuts (e.g., F for File, E for Edit, T for Tool, H for Help, etc.) instead of down-arrows, but that particular context menu (via Shift+F10) doesn't have access key shortcuts. I don't know of a good solution for this.

Furthermore, some search results don't even have an "Open file location" menu pick. For example, search for "calc" and then do a Shift+F10 on Calculator — there is no "Open file location" choice. Regards, Joe
Joe,
Thank you for this update.
I tried many times with your proposal but I am still unable to run it.
I don’t if ahk is blocked when menu bar is in front.
I am blocked,.
I attached my video.
I don’t know if I can try to put a ifwinactive loop to make it work.
Thank you for your help.
2019-07-30_15h43_14.mp4
Hi Luis,
There's no audio in your video, but I think what's happening at the end of the video is that Ctrl+F8 is not firing. The reason is that you didn't properly terminate the #IfWinActive directive above it, so the ^F8 below it is under the influence of that #IfWinActive directive. Remember what I said in one of our previous threads about the context sensitivity of hotkeys/hotstrings in AutoHotkey scripts:
Btw, all of the #IfWin directives are positional, i.e., they affect all hotkeys and hotstrings beneath them in the script. To turn off the context sensitivity of an #IfWin directive, code the directive without any parameters.
So, after the Return command in your #IfWinActive,ahk_class CabinetWClass hotkey, put this:

#IfWinActive

Open in new window

Then ^F8 (and all other hotkeys under it) will work properly, since they'll no longer be under the influence of that #IfWinActive, which, of course, is there so that the hotkey will work only in File Explorer.

Also, remember my other comment (bolding added):
Btw, you don't technically have to end an #If or #IfWin if there is another one below it, since they are mutually exclusive, i.e., only the most recent one will be in effect. However, I prefer to be explicit in ending them and I think it is good programming practice.
All of that said, the script won't work on the .xlsm file because the script in your video does a Down 2, but the .xlsm file requires only one down-arrow to get to the "Open file location" menu pick. That's what I tried to explain in the "Update" at my previous post. Depending on the file type, you may need one down-arrow or two down-arrows, and maybe more in some cases...I don't know...but I do know in some cases that there isn't even an "Open file location" menu pick.

As you know, I'm a huge fan of automation with AutoHotkey, but in this particular case, my advice is not to pursue this because, unless you use it only when searching certain file types, you'll never know what the first menu item pick is going to be. Regards, Joe
Thank you Joe, unable to test it right now. I will keep you informed.
Thank you for your help.
You're welcome, Luis, looking forward to the results of your testing. Regards, Joe
Joe, you were totally right.
I put code above ahk which use #ifWinActive and it works so it was under the influence of this and you were totally right.
Prior to putting #IfWinActive off I would like to know what the best because I have on my compiled ahk. file multiple #IfWinActive:
1-Turn off each of them (individually)
;====================================
; Sort by modified date
;====================================
#IfWinActive,ahk_class CabinetWClass
+F3::
Send, !vo
Sleep, 25
Send, {Down}{Enter}
Return
#IfWinActive

;====================================
; 7zip
;====================================

#IfWinActive,ahk_class CabinetWClass
+F7::
Send, +{F10}
Sleep, 5
Send, 7
Return
#IfWinActive

Open in new window


2-Or just one time
;====================================
; Sort by modified date
;====================================
#IfWinActive,ahk_class CabinetWClass
+F3::
Send, !vo
Sleep, 25
Send, {Down}{Enter}
Return


;====================================
; 7zip
;====================================

#IfWinActive,ahk_class CabinetWClass
+F7::
Send, +{F10}
Sleep, 5
Send, 7
Return
#IfWinActive

Open in new window


As for the open file location you were right, sometimes it required 2*down and sometimes 1*down but I realized that 2*down was in particular for .ahk files (as far I am concern). Knowing that I never open ahk through this option because I use SciTe4. I will figured out to keep it active or not.
In any case thank you for your help.
> 1-Turn off each of them (individually)

Yes! As I mentioned earlier, you don't technically have to do this if there is another one below it, since they are mutually exclusive, but it is good programming practice to be explicit in ending each one. That will "future-proof" your AutoHotkey script so that if, for example, you add a non-context-sensitive hotkey/hotstring after a context-sensitive one, it will work, because you properly ended the prior context-sensitive one.

> Knowing that I never open ahk through this option because I use SciTe4.

OK, then it sounds as if {Down 1} (or just {Down}, of course) will work well for you. Regards, Joe
Thank you Joe! Very clear.
Just last question about turning off context. You mentioned that it should place right after return. What I don't understand is why not just before return because I thought that return is the last part of your ahk script.
Sorry for this question but if I understand this I can move forward on context sensitivity and apply the right approach.
> I thought that return is the last part of your ahk script

No! The Return statement returns from a subroutine or function call, which includes returning from the firing of a hotkey/hotstring. You should study the doc here:
https://www.autohotkey.com/docs/commands/Return.htm

For example. a single AutoHotkey script can have hundreds of hotkeys/hotstrings defined in it...each one finishes its task when it executes a Return.

I just checked my AHK hotkeys/hotstrings script that runs when Windows starts...it has 197 Return statements in it. :)

I then checked the most recent large program that I wrote in AHK...it has nothing to do with hotkeys/hotstrings...it has 219 Return statements in it...all are returns from subroutine or function calls. Regards, Joe
Noted Joe, thank you again for your help and your in-depth advice.
You're welcome, Luis. I'm glad to see that you are getting such good value from AutoHotkey. Regards, Joe