If Window Does Not Exist Continue Autohotkey

  • Members
  • 31 posts
  • Last active: Aug 28 2015 11:12 AM
  • Joined: 25 Apr 2013

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"            

  • Back to top

kon

  • Members
  • 1652 posts
  • Last active:
  • Joined: 04 Mar 2013

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 }

  • Back to top

Janulinka

  • Members
  • 31 posts
  • Last active: Aug 28 2015 11:12 AM
  • Joined: 25 Apr 2013

I do not know how can I use you be more specific please..


  • Back to top

kon

  • Members
  • 1652 posts
  • Last active:
  • Joined: 04 Mar 2013

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 }

  • Back to top

MasterFocus

  • Moderators
  • 4323 posts
  • Last active: Jan 28 2016 01:38 AM
  • Joined: 08 Apr 2009
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

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

Janulinka

  • Members
  • 31 posts
  • Last active: Aug 28 2015 11:12 AM
  • Joined: 25 Apr 2013

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... sad.png

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


  • Back to top

Janulinka

  • Members
  • 31 posts
  • Last active: Aug 28 2015 11:12 AM
  • Joined: 25 Apr 2013

No one help ? sad.png


  • Back to top

vsub

  • Members
  • 1098 posts
  • Last active: Sep 28 2015 09:48 AM
  • Joined: 10 Nov 2011

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


  • Back to top

kon

  • Members
  • 1652 posts
  • Last active:
  • Joined: 04 Mar 2013

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." }

  • Back to top

JadeDragon

  • Members
  • 935 posts
  • Last active: Jun 07 2014 07:40 AM
  • Joined: 18 Jan 2013

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

  1. the idea or concept for a script
  2. a complete description of what the script is supposed to do
  3. the ability to communicate clearly and unambiguously the purpose and needs of the script to others
  4. the ability to know when the script is performing properly
  5. the ability to create, build, program or otherwise produce a script that actually does what is intended
  6. 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.


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

Janulinka

  • Members
  • 31 posts
  • Last active: Aug 28 2015 11:12 AM
  • Joined: 25 Apr 2013

JadeDragon: I'll write you something intelligible: <CENSORED>

Moderator's note: watch your language


  • Back to top

kon

  • Members
  • 1652 posts
  • Last active:
  • Joined: 04 Mar 2013

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?


  • Back to top

kon

  • Members
  • 1652 posts
  • Last active:
  • Joined: 04 Mar 2013

✓  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" }

  • Back to top

JadeDragon

  • Members
  • 935 posts
  • Last active: Jun 07 2014 07:40 AM
  • Joined: 18 Jan 2013

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.


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

Rijul Ahuja

  • Members
  • 763 posts
  • Last active: Nov 25 2013 10:16 AM
  • Joined: 14 Mar 2012

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.


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

tannerfigother.blogspot.com

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

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel