- Run in the background and whenever an Explorer folder is activated, store that folder's filepath in a variable. If a new folder is activated, the new filepath replaces the previous one, so there is always just one filepath stored.
- Whenever the "Save as" window pops up, the default save location (which is almost never what I need it to be) will be changed to the last stored filepath. The "Save as" window doesn't need to already show up on the desired location, something like Ctrl + L to select the address bar and pasting the stored filepath would be enough.
How to store last active folder's filepath and paste it when the "Save as" window pops up
How to store last active folder's filepath and paste it when the "Save as" window pops up
I want a script that will do the following:
- WarlordAkamu67
- Posts: 232
- Joined: 21 Mar 2023, 06:52
Re: How to store last active folder's filepath and paste it when the "Save as" window pops up
Hello.
This worked for me. Tested trying to save Adobe Illustrator files.
This worked for me. Tested trying to save Adobe Illustrator files.
Code: Select all
#Requires AutoHotkey v2.0+
#SingleInstance
SetTimer(checkforFolder, 100)
; ------------------------- ; ------------------------- ; ------------------------- ; ------------------------- ; ------------------------- ; ------------------------- ; ------------------------- ; ------------------------- ; ------------------------- ; ------------------------- ;
; ------------------------- ; ------------------------- ; ------------------------- ; ------------------------- ; ------------------------- ; ------------------------- ; ------------------------- ; ------------------------- ; ------------------------- ; ------------------------- ;
; ------------------------- ; ------------------------- ; ------------------------- ; ------------------------- ; ------------------------- ; ------------------------- ; ------------------------- ; ------------------------- ; ------------------------- ; ------------------------- ;
get_Active_Explorer_Path() {
explorerHwnd := WinActive("ahk_class CabinetWClass")
if (explorerHwnd) {
for window in ComObject("Shell.Application").Windows {
if (window.hwnd==explorerHwnd) {
return(window.Document.Folder.Self.Path)
}
}
}
return(0)
}
; ------------------------- ; ------------------------- ; ------------------------- ; ------------------------- ; ------------------------- ; ------------------------- ; ------------------------- ; ------------------------- ; ------------------------- ; ------------------------- ;
checkforFolder() {
static folderPath := ""
if (pathString := get_Active_Explorer_Path()) {
folderPath := pathString
} else if (WinActive("Save As")) {
Send("^l")
Sleep(100)
SendText(folderPath)
Sleep(100)
Send("{enter}")
WinWaitClose("Save As")
}
return
}
- WarlordAkamu67
- Posts: 232
- Joined: 21 Mar 2023, 06:52
Re: How to store last active folder's filepath and paste it when the "Save as" window pops up
I receive an error when closing the window. Will update when I can, or if someone else has a solution? I didn't want to just throw it into a try block.
- Attachments
-
- error.png (13.58 KiB) Viewed 877 times
Re: How to store last active folder's filepath and paste it when the "Save as" window pops up
Saving the path is not needed.
Spoiler
- Attachments
-
- nil.jpg (631 Bytes) Viewed 248 times
Last edited by rommmcek on 18 Feb 2024, 07:48, edited 29 times in total.
Re: How to store last active folder's filepath and paste it when the "Save as" window pops up
Thanks for the script, but it is way too advanced for me. Could you explain me in general terms what it is doing, particulartly why I need the Ctrl+F3 hotkey and why it sends Alt+d?
Re: How to store last active folder's filepath and paste it when the "Save as" window pops up
I asked ChatGPT...
P.p.s.: Script has potential flaws have new versions, no time now, report issues.
Spoiler
P.s.: !d does essentially the same as ^l, but now I know how to do it without any of these.P.p.s.: Script has potential flaws have new versions, no time now, report issues.
Last edited by rommmcek on 24 Jan 2024, 21:25, edited 1 time in total.
Re: How to store last active folder's filepath and paste it when the "Save as" window pops up
Unfortunately it's not working for me. I made some changes to the script, but still no luck. Here is the exact same script I'm using:
Code: Select all
#Requires AutoHotkey v2+
#SingleInstance
SetTitleMatchMode 2
loop {
WinWaitActive "Save ahk_class #32770"
if (explrPath:=get_Active_Explorer_Path())&&!InStr(explrPath, "{") {
Send "^l" ; !d does not select the address bar in my computer.
try While !ControlGetVisible("Edit2", "A")
Continue
While explrPath!=ControlGetText("Edit2", "A")
ControlSetText explrPath, "Edit2", "A" ;Address bar is more responsive
ControlSend "{Enter}", "Edit2", "ahk_class #32770" ;Using Class is less general
try While !ControlGetVisible("ToolbarWindow324", "A")
Continue
ControlFocus "Edit1", "A"
} WinWaitNotActive "Save ahk_class #32770"
}
^F2:: { ;the hotkey for some 'default' path. >>> I already use ^F3 for something else, so I changed it to ^F2
Static defaultPath:= "C:\Users\flima\Downloads" ;set your 'default' path
if !FileExist(defaultPath)
Return
Send "^l"
try While !ControlGetVisible("Edit2", "A")
Continue
While defaultPath!=ControlGetText("Edit2", "A")
ControlSetText defaultPath, "Edit2", "A"
ControlSend "{Enter}", "Edit2", "ahk_class #32770" ;Using Class is less general
try While !ControlGetVisible("ToolbarWindow324", "A")
Continue
ControlFocus "Edit1", "A"
}
get_Active_Explorer_Path() {
explorerHwnd:= WinExist("ahk_class CabinetWClass")
if (explorerHwnd) {
for window in ComObject("Shell.Application").Windows {
if (window.hwnd==explorerHwnd) {
return(window.Document.Folder.Self.Path)
}
}
} return(0)
}
Re: How to store last active folder's filepath and paste it when the "Save as" window pops up
For me on Win10 works your version too. On Win11 I can test it only in the weekend.
Now we have to debug it. First try to run the script as Administrator.
Then, start by sections as declared by ChatGPT (I edited it to be better shown).
Now we have to debug it. First try to run the script as Administrator.
Then, start by sections as declared by ChatGPT (I edited it to be better shown).
E.g.:
Last edited by rommmcek on 28 Jan 2024, 06:37, edited 1 time in total.
Re: How to store last active folder's filepath and paste it when the "Save as" window pops up
Indeed on Win11 in some applications there was a problem and even on Win10 on some "asleepy" browser (that was not used for a prolonged period of time) the FileName Control did not focus after the Path setting...
I edited the code to be more robust yet still fast and updated the post above.
P.s.: Since e.g. launching Win Explorer from batch file, doesn't seem to support COM, I rewrote code based only on ControlGet/ControlSet. Sending Enter is dangerous, so is changing Folder via File-name Control.
Updated the post above, it should work on Win11 too (now only one safe version, but working on Open dialog too).
I edited the code to be more robust yet still fast and updated the post above.
P.s.: Since e.g. launching Win Explorer from batch file, doesn't seem to support COM, I rewrote code based only on ControlGet/ControlSet. Sending Enter is dangerous, so is changing Folder via File-name Control.
Updated the post above, it should work on Win11 too (now only one safe version, but working on Open dialog too).
Last edited by rommmcek on 18 Feb 2024, 07:35, edited 1 time in total.
Re: How to store last active folder's filepath and paste it when the "Save as" window pops up
Finished the script above.
Hope I'll get some feedback from both Win10 & Win11.
Hope I'll get some feedback from both Win10 & Win11.