Hello I am trying to make a script to open a specific folder and if it is already opened to close it.
Right now I have a script only to open the folder:
^F10::
Run C:\Users\XXX\Desktop\X3 Attachement
Return
Open Folder and Close if already open
-
- Posts: 862
- Joined: 21 Dec 2015, 02:34
Re: Open Folder and Close if already open
Code: Select all
Window=X3 Attachement
^f10::
IfWinExist, %Window%
Winclose, %Window%
else
run, C:\Users\XXX\Desktop\%Window%
Return
Re: Open Folder and Close if already open
thank you very much! it worked like a charm!
Re: Open Folder and Close if already open
So I tried adding onto the script by having it do the same for a different folder and it seem to work the first time but after that it only opens and closes the Estimate folder:
Code: Select all
Window=X3 Attachement
^f10::
IfWinExist, %Window%
Winclose, %Window%
else
run, C:\Users\XXX\Desktop\%Window%
Return
^f9::
Window=Estimates
IfWinExist, %Window%
Winclose, %Window%
else
run, C:\Users\XXX\Desktop\%Window%
Return
Re: Open Folder and Close if already open
the variable "Window" is set to "X3 Attachment" only at the start of the script (auto-execution section) and not again when you press ^f10. see my change below.Hubert
Code: Select all
^f10::
Window=X3 Attachement
IfWinExist, %Window%
Winclose, %Window%
else
run, C:\Users\XXX\Desktop\%Window%
Return
Re: Open Folder and Close if already open
Potential issues:
Edit: Changed window.LocationURL to window.Document.Folder.Self.Path as jeeswg suggested.
Edit2: Changed WinClose, % "ahk_id " window.hWnd to Window.Quit.
- Different folders path may have the same folder name.
- The window title could be the folder name or path based on user settings.
Code: Select all
^f10::FolderToggleOpen("C:\Users\XXX\Desktop\X3 Attachement")
^f9::FolderToggleOpen("C:\Users\XXX\Desktop\Estimates")
FolderToggleOpen(FolderPath) {
For Window In ComObjCreate("Shell.Application").Windows {
If (RTrim(Window.Document.Folder.Self.Path, "\") = RTrim(FolderPath, "\"))
Return Window.Quit
}
Run, % FolderPath
}
Edit2: Changed WinClose, % "ahk_id " window.hWnd to Window.Quit.
Last edited by tmplinshi on 20 Jul 2019, 08:46, edited 2 times in total.
Re: Open Folder and Close if already open
@tmplinshi: One thing to consider is this. Cheers.
RTrim(window.Document.Folder.Self.Path, "\")
RTrim(window.Document.Folder.Self.Path, "\")
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Re: Open Folder and Close if already open
Oh, nice. I didn't know that. Thanks jeeswg!
-
- Posts: 4347
- Joined: 29 Mar 2015, 09:41
- Contact:
Re: Open Folder and Close if already open
@jeeswg
Is RTrim really needed?
Is RTrim really needed?
Code: Select all
for window in ComObjCreate("Shell.Application").Windows
MsgBox, % window.Document.Folder.Self.Path
Re: Open Folder and Close if already open
For most paths, there is no trailing backslash.
An exception is the root of the drive e.g. C:\.
An exception is the root of the drive e.g. C:\.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
-
- Posts: 4347
- Joined: 29 Mar 2015, 09:41
- Contact:
Re: Open Folder and Close if already open
Right, thanks.
Re: Open Folder and Close if already open
thank you very much everyone!
Who is online
Users browsing this forum: No registered users and 118 guests