| View previous topic :: View next topic |
| Author |
Message |
jak
Joined: 28 Feb 2006 Posts: 159
|
Posted: Sat Feb 14, 2009 6:50 am Post subject: how detect if another ahk file is running |
|
|
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 |
|
 |
sinkfaze
Joined: 18 Mar 2008 Posts: 5043 Location: the tunnel(?=light)
|
|
| Back to top |
|
 |
jak
Joined: 28 Feb 2006 Posts: 159
|
Posted: Sat Feb 14, 2009 8:25 am Post subject: |
|
|
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 |
|
 |
SKAN
Joined: 26 Dec 2005 Posts: 8688
|
Posted: Sat Feb 14, 2009 9:05 am Post subject: |
|
|
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 |
|
 |
sinkfaze
Joined: 18 Mar 2008 Posts: 5043 Location: the tunnel(?=light)
|
Posted: Sat Feb 14, 2009 4:19 pm Post subject: |
|
|
| 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 |
|
 |
jak
Joined: 28 Feb 2006 Posts: 159
|
Posted: Sun Feb 15, 2009 3:15 am Post subject: |
|
|
| SKAN, thank you, i'll try that. |
|
| Back to top |
|
 |
|