Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Keep a save/open folder consistent across several apps
/*
PersistentSaveFolder.ahk
Version 1.0.10ex
March 28, 2018
burque505
*/
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
#Persistent
SetTitleMatchMode, 2
global saveFolder := ""
;This script is to combat the aggravation of each application
;not keeping track of your working folder. Say you're working on a
;customer's account, and you need to use Excel, Word, Acrobat, and
;maybe your email account - who knows.
;Each one of these applications is unlikely to know which folder you'd
;prefer to jump to in Explorer, or to open from/save in any
;#32770 (Open/Save) dialog. And is guaranteed, almost, to hammer it on
;the next open, save or jump. Arrgh ...
;
;The script isn't fancy. There are no settings or bells or whistles.
;Customze as you see fit.
;
;FOR NOW ...
;Ctrl-Win-S will set the open/save folder from an open/save dialog or from an open Explorer window.
;Ctrl-Win-J will jump to that folder in an open/save dialog or in Explorer
;Ctrl-Win-C clears the folder setting.
;Ctrl-Win-Q queries the set folder.
;Shift+Escape bails.
;
;You'll probably want to mod the msgbox delays or get rid of the msgboxes
;entirely once you get used to the script.
;
;Only tested so far with Word, Excel, Powerpoint, Acrobat, Explorer, Thunderbird,
;Scite4AutoHotkey, Outlook, Notepad, Firefox 57, IE 11, Pale Moon 27 (32-bit)
;
;Comments and suggestions heartily welcome.
;There's lots of room for improvement.
;The indentation is inconsistent.
;
;Regards, burque505
^#j::
;If an Explorer window or an open/save dialog is open, set the jump/save folder
If (saveFolder == "" && (WinActive("ahk_class #32770") || WinActive("ahk_class CabinetWClass"))) {
msgbox, , , No SAVE/JUMP folder set - defaulting to Documents, 2
saveFolder := "C:\Users\%username%\Documents"
}
saveHere()
return
^#s::
setSaveFolder()
return
^#c::
saveFolder := ""
msgbox, , , SAVE/JUMP FOLDER CLEARED!, 1
return
^#q::
If (saveFolder == "")
{
msgbox, , , No Jump/Save Folder Set!, 2
}
else
{
msgbox, , , Jump/Save folder is:`n%saveFolder%, 3
}
return
setSaveFolder() {
;Word, Excel or Powerpoint deviations from standard #32770 behavior
;Thunderbird is particularly irksome. It is slow, so long delays are necessary.
;At least my present machine :)
If (WinActive("ahk_class #32770") && WinActive("ahk_exe thunderbird.exe"))
{
;More T-bird workarounds, March 28, 2018
If (WinActive("Attach file\(s\) ahk_class #32770") || WinActive("Save Message As ahk_class #32770")) { ;begin interior "If"
msgbox in attach or save
ControlFocus, DirectUIHWND2, ahk_class #32770
}
Else {
ControlFocus, Edit2, ahk_class #32770
}
sleep, 300
send, !d
sleep, 300
ControlGetText, saveFolder, Edit2, ahk_class #32770
sleep, 100
msgbox, , , Open/Save/Attach folder is:`n%saveFolder% in Thunderbird, 2
}
Else if WinActive("ahk_class #32770"){
If (WinActive("ahk_exe WINWORD.EXE") || WinActive("ahk_exe EXCEL.EXE") || WinActive("ahk_exe POWERPNT.EXE"))
; Annoyingly enough, there are different Edit class numbers for Open and Save As. This section deals with it.
{
ControlFocus, DirectUIHWND2, ahk_class #32770
Send, !d
If (WinActive("Open ahk_class #32770")) { ; Begin interior "If"
ControlGetText, saveFolder, Edit2, ahk_class #32770
}
Else {
ControlGetText, saveFolder, Edit3, ahk_class #32770
} ; End interior If
msgbox, , , Open/Save folder is:`n%saveFolder% in Office Open/Save Dialog, 2
} ; End surrounding "If"
else
;Acrobat, Notepad, Scite, Outlook, probably lots of others work with this.
{
Send, !d
Sleep, 100
ControlGetText, saveFolder, Edit2, ahk_class #32770
msgbox, , , Open/Save folder is:`n%saveFolder% in Save, 2
;the delay above (2 seconds) is probably too long.
}
}
else if (WinActive("ahk_class CabinetWClass")) {
Send, !d
Sleep, 100
ControlGetText, saveFolder, Edit1, ahk_class CabinetWClass
msgbox, , , Jump/Save folder is:`n%saveFolder% in Explorer, 2
;the delay above (2 seconds) is probably too long.
}
else {
msgbox, , ,No Explorer - no open or save dialog activated, 1
}
}
saveHere() {
If WinActive("ahk_class #32770")
{
Send, !d
Sleep, 300
SendInput, {Raw}%saveFolder%
Sleep, 100
SendInput, {Enter}
}
else if WinActive("ahk_class CabinetWClass")
{
Send, !d
Sleep, 300
ControlSetText, Edit1, %saveFolder%, ahk_class CabinetWClass
Sleep, 100
Send, {Enter}
}
else {
msgbox, , ,No Explorer - no open or save dialog activated, 1
}
}
+Escape::ExitApp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.