If Window Does Not Exist Continue Autohotkey
Hello
Do not open the window if already exists
+ If the window is open a window in the foreground
#A::Run explorer.exe "C:\A\A" #B::Run explorer.exe "C:\B\B" #C::Run explorer.exe "C:\C\C"
#1 - Posted 02 July 2013 - 11:04 PM
- Back to top
Maybe something like this:
#a::WinShortcut("C:\A\A") #b::WinShortcut("C:\B\B") #c::WinShortcut("C:\C\C") WinShortcut(Path) { IfWinExist, %Path% { WinActivate, %Path% return 1 } Run explorer.exe %Path% return 0 }
#2 - Posted 02 July 2013 - 11:29 PM
- Back to top
I do not know how can I use you be more specific please..
#3 - Posted 02 July 2013 - 11:42 PM
- Back to top
You just need to change the top lines. Leave the rest unchanged.
#a::WinShortcut("Change this to a new path") #b::WinShortcut("C:\B\B") #c::WinShortcut("C:\C\C") ;-----------Don't change anything below this line----------- WinShortcut(Path) { IfWinExist, %Path% { WinActivate, %Path% return 1 } Run explorer.exe %Path% return 0 }
#4 - Posted 03 July 2013 - 12:49 AM
- Back to top
#5 - Posted 03 July 2013 - 12:51 AM
Antonio França -- git.io -- github.com -- ahk4.net -- sites.google.com -- ahkscript.org Member of the AHK community since 08/Apr/2009. Moderator since mid-2012.
- Back to top
You just need to change the top lines. Leave the rest unchanged.
#a::WinShortcut("Change this to a new path") #b::WinShortcut("C:\B\B") #c::WinShortcut("C:\C\C") ;-----------Don't change anything below this line----------- WinShortcut(Path) { IfWinExist, %Path% { WinActivate, %Path% return 1 } Run explorer.exe %Path% return 0 }
I understand that I need to change the paths to folders
But just not working for me...
I want one (open window) to get themselves into the foreground If you press the key combination again
MasterFocus: That does not help me I don't understand how to use it
#6 - Posted 03 July 2013 - 11:33 AM
- Back to top
No one help ?
#7 - Posted 03 July 2013 - 03:19 PM
- Back to top
What part of it don't work?
If it's the Run part,try changing it like this
Run explorer.exe "%Path%"
Also the default SetTitleMachMode is 1(must begin with that)so if the window don't begin with exactly that,it won't activate the window.
When SetTitleMachMode is not added to the code,mode 1 will be used,mode 1 match everywhere and mode 3 match the whole title
#8 - Posted 03 July 2013 - 05:12 PM
- Back to top
Try running this. What do the message boxes say?
#a:: Var := WinShortcut("C:\Program Files") MsgBox % Var return #b:: Var := WinShortcut("C:\B\B") MsgBox % Var return #c:: Var := WinShortcut("C:\C\C") MsgBox % Var return WinShortcut(Path) { IfWinExist, %Path% { WinActivate, %Path% return "Folder was activated." } if (!FileExist(Path)) return "Folder does not exist." Run explorer.exe %Path%,, UseErrorLevel if (ErrorLevel) return "Run failed." return "Folder was opened." }
#9 - Posted 03 July 2013 - 05:36 PM
- Back to top
When scripting just like using any computer language to create a program, several things have to come together all at the same time in the same place
- the idea or concept for a script
- a complete description of what the script is supposed to do
- the ability to communicate clearly and unambiguously the purpose and needs of the script to others
- the ability to know when the script is performing properly
- the ability to create, build, program or otherwise produce a script that actually does what is intended
- the ability to find and fix any problems that prevent the script from performing it's function
Without those no well defined script or in fact any computer program will be produced; and all efforts to do so will end in frustration and failure.
#10 - Posted 03 July 2013 - 08:18 PM
Never assume evil intent when simple ignorance will suffice. Ignorance is an eventually curable condition with the right education. Evil intent, however, is another matter entirely. Scripts are much like children. Simple to conceive. Difficult, expensive, and time-consuming to raise. Often do the opposite of what you expect them to. Require frequent "correction". And once they leave home you can't control them anymore. But you love them anyway.
- Back to top
JadeDragon: I'll write you something intelligible: <CENSORED>
Moderator's note: watch your language
#11 - Posted 03 July 2013 - 11:34 PM
- Back to top
Edit: Disregard this post. See my next post.
Sorry Janulinka, I think I found the problem. The computer I was on before used the full path as the window title. After I tested it on another computer I saw that it uses only the folder name as the window title - I think that is why my code did not work for you before. This code just uses the folder name as the window title when it activates a window:
Spoiler
#a::WinShortcut("C:\Program Files") ;Win+a #b::WinShortcut("C:\B\B") ;Win+b #c::WinShortcut("C:\C\C") ;Win+c WinShortcut(Path) { RegExMatch(Path, "[^\\]+$", Title) ;get the folder name IfWinExist, %Title% ;check if the win exists { WinActivate, %Title% return "Activated" } if (!FileExist(Path)) ;check if folder exists { TrayTip, , Folder does not exist. return "Folder does not exist." } Run explorer.exe %Path%,, UseErrorLevel ;open the folder if (ErrorLevel) return "Run failed." return "Opened." }
If this doesn't work I suggest taking another look at the link MasterFocus provided. There are some examples of assigning various windows to hotkeys at the end of the code in the first post. It seems like that script has more features than the one I made.
@JadeDragon - Were those comments directed towards me or the OP or both? They seem like some good ideals to keep in mind. I was violating many, if not all, of those precepts. But I am still learning; if I only pick problems to work on that I have already mastered I won't learn. Do you have any comments relating specifically to the code I or anyone else has posted in this thread?
#12 - Posted 04 July 2013 - 01:43 AM
- Back to top
✓ Best Answer
Best Answer
Actually I thought about it, and I think a better way would be to use a second parameter in the function for the win title (like was done in the post MasterFocus linked to.
;examples #a::WinShortcut("C:\Program Files (x86)\Mozilla Firefox\firefox.exe", "ahk_class MozillaWindowClass") ;Win+a open/activate firefox #b::WinShortcut("C:\B\B", "B") ;Win+b open/activate a folder #c::WinShortcut("C:\C\C", "C") ;Win+c open/activate a folder #d::WinShortcut("C:\Program Files", "Program Files") ;Win+d open/activate Program Files WinShortcut(Path, Title) { IfWinExist, %Title% ;check if the win exists { WinActivate, %Title% return "Activated" } if (!FileExist(Path)) ;check if file exists { TrayTip, , File does not exist. return "File does not exist" } Run %Path%,, UseErrorLevel ;open the folder/file if (ErrorLevel) return "Run failed" return "Opened" }
#13 - Posted 04 July 2013 - 02:16 AM
- Back to top
I refuse to take offense at your previous post Janulinka. The whole purpose of my post was to express what is required between BOTH the person making a request for script help AND the person who is attempting to help. If communication between them fails at any point in the requirements i listed before it simply frustrates both people and no reliable script gets produced. It's important to realize that precise communication is a key ingredient for making scripts whether it's talking to a person or a computer through a scripting language. If my post offended you please accept my sincere apology and realize that my post was offered only with the best of intentions.
#14 - Posted 04 July 2013 - 05:21 AM
Never assume evil intent when simple ignorance will suffice. Ignorance is an eventually curable condition with the right education. Evil intent, however, is another matter entirely. Scripts are much like children. Simple to conceive. Difficult, expensive, and time-consuming to raise. Often do the opposite of what you expect them to. Require frequent "correction". And once they leave home you can't control them anymore. But you love them anyway.
- Back to top
Actually I thought about it, and I think a better way would be to use a second parameter in the function for the win title (like was done in the post MasterFocus linked to.
Spoiler
;examples #a::WinShortcut("C:\Program Files (x86)\Mozilla Firefox\firefox.exe", "ahk_class MozillaWindowClass") ;Win+a open/activate firefox #b::WinShortcut("C:\B\B", "B") ;Win+b open/activate a folder #c::WinShortcut("C:\C\C", "C") ;Win+c open/activate a folder #d::WinShortcut("C:\Program Files", "Program Files") ;Win+d open/activate Program Files WinShortcut(Path, Title) { IfWinExist, %Title% ;check if the win exists { WinActivate, %Title% return "Activated" } if (!FileExist(Path)) ;check if file exists { TrayTip, , File does not exist. return "File does not exist" } Run %Path%,, UseErrorLevel ;open the folder/file if (ErrorLevel) return "Run failed" return "Opened" }
I think that would be the best approach.
#15 - Posted 04 July 2013 - 05:27 AM
Abandon the forum. The community has decided in a democratic vote to leave this website because of inactive and perverse administration.
Very few of the contributing members remain here.
- Back to top
Source: https://www.autohotkey.com/board/topic/95034-do-not-open-the-window-if-already-exists/
0 Response to "If Window Does Not Exist Continue Autohotkey"
Post a Comment