AutoHotkey Community

It is currently May 26th, 2012, 6:21 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 6 posts ] 
Author Message
PostPosted: February 14th, 2009, 7:50 am 
Offline

Joined: February 28th, 2006, 8:42 am
Posts: 159
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...


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 14th, 2009, 8:15 am 
Offline
User avatar

Joined: March 19th, 2008, 12:43 am
Posts: 5480
Location: the tunnel(?=light)
Why not use #SingleInstance Ignore?

_________________
Image
Try Quick Search for Autohotkey or see the tutorial for newbies.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 14th, 2009, 9:25 am 
Offline

Joined: February 28th, 2006, 8:42 am
Posts: 159
sinkfaze 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?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 14th, 2009, 10:05 am 
Online
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8776
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 14th, 2009, 5:19 pm 
Offline
User avatar

Joined: March 19th, 2008, 12:43 am
Posts: 5480
Location: the tunnel(?=light)
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.

_________________
Image
Try Quick Search for Autohotkey or see the tutorial for newbies.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 15th, 2009, 4:15 am 
Offline

Joined: February 28th, 2006, 8:42 am
Posts: 159
SKAN, thank you, i'll try that.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: batto, Bing [Bot], rbrtryn, SKAN and 59 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group