AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

how detect if another ahk file is running

 
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
jak



Joined: 28 Feb 2006
Posts: 159

PostPosted: Sat Feb 14, 2009 6:50 am    Post subject: how detect if another ahk file is running Reply with quote

I want my main ahk file, to check for a certain window, and if that window exists, to launch a second ahk file (if and only if it is not already running).

having trouble doing this that part that is in bold font.

I can detect the window with a timer:

Code:
settimer, checkwindow, 500
return

checkwindow:
if winexist, my window
{
if [detect if "mysecondahk" is running or not]
;if its not running,
run mysecondahk.ahk
}
;else
return

The reason I'm having trouble detecting whether 'mysecondahk' is running or not, is because I'm not able to capture its ID and title and etc using "windowspy".

help! thanks...
Back to top
View user's profile Send private message
sinkfaze



Joined: 18 Mar 2008
Posts: 5043
Location: the tunnel(?=light)

PostPosted: Sat Feb 14, 2009 7:15 am    Post subject: Reply with quote

Why not use #SingleInstance Ignore?
_________________
Try Quick Search for Autohotkey or see the tutorial for newbies.
Back to top
View user's profile Send private message Send e-mail
jak



Joined: 28 Feb 2006
Posts: 159

PostPosted: Sat Feb 14, 2009 8:25 am    Post subject: Reply with quote

sinkfaze wrote:
Why not use #SingleInstance Ignore?


well, that seems wasteful doesnt it? I mean in terms of a hit on performance. Wouldnt the first script continually (every 1/2 second) try to launch the second script even when it doesnt have to?
Back to top
View user's profile Send private message
SKAN



Joined: 26 Dec 2005
Posts: 8688

PostPosted: Sat Feb 14, 2009 9:05 am    Post subject: Reply with quote

A working example. mysecondahk.ahk will run and exit along with Calculator
Code:
#Persistent
DetectHiddenWindows, On
SetTitleMatchMode, 2
SetTimer, CheckWindow, 500
Return

CheckWindow:
IfWinExist, Calculator
 {
  IfWinNotExist, mysecondahk.ahk ahk_class AutoHotkey
    Run mysecondahk.ahk
 }
Else PostMessage,0x111,65405,0,,% "ahk_id" WinExist( "mysecondahk.ahk ahk_class AutoHotkey")
Return


Code:
;mysecondahk.ahk
Gui +LastFound
Back to top
View user's profile Send private message Send e-mail
sinkfaze



Joined: 18 Mar 2008
Posts: 5043
Location: the tunnel(?=light)

PostPosted: Sat Feb 14, 2009 4:19 pm    Post subject: Reply with quote

jak wrote:
well, that seems wasteful doesnt it? I mean in terms of a hit on performance. Wouldnt the first script continually (every 1/2 second) try to launch the second script even when it doesnt have to?


#SingleInstance Ignore wrote:
The word IGNORE skips the dialog box and leaves the old instance running. In other words, attempts to launch an already-running script are ignored.


Seems to me like that's what you'd be looking for. If script 2 isn't running, script 1 can run it, if it is running the script 1's attempt to run it will be ignored.
_________________
Try Quick Search for Autohotkey or see the tutorial for newbies.
Back to top
View user's profile Send private message Send e-mail
jak



Joined: 28 Feb 2006
Posts: 159

PostPosted: Sun Feb 15, 2009 3:15 am    Post subject: Reply with quote

SKAN, thank you, i'll try that.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group