Looping AppleScript

Joined
May 31, 2011
Messages
10
Reaction score
0
Points
1
I am writing a very basic AppleScript program that I want to always be running in the background. Is the best way to do this just to start the script and have an infinitle loop in it? My program is merely checking if another program is open and if it is it is starting another program. For example, if program A is opened then program B is started.

Is there a better way to write this other than just putting my entire program in a neverending repeat loop?

Thanks
 
Joined
May 14, 2009
Messages
2,052
Reaction score
136
Points
63
Location
Near Whitehorse, Yukon
Your Mac's Specs
2012 MBP i7 2.7 GHz 15" Matte - 16 GB RAM - 120 GB Intel SSD - 500 GB DataDoubler Mac OS 10.9
Hmm, having it running all the time wouldn't be too good as it will take a quite a chunk of you CPU power.

I would add a small section to the top of the applescript that you already have that will open program A.
Then instead of opening program A, open the Applescript instead which will open A and then B.
 
Joined
Aug 2, 2011
Messages
16
Reaction score
0
Points
1
G'day

You do this with an idle handler

Code:
on idle
    -- your script for starting B if A is opened
    return 5
end idle
save it as an application. make sure you check the 'stay open' option.

as you say, this needs to be always running — the idle handler will repeat your checking script, in this example, every 5 seconds (if you delete the 'return 5' it will run every 30 seconds by default).

Hope this is what you're looking for

m.
 

Shop Amazon


Shop for your Apple, Mac, iPhone and other computer products on Amazon.
We are a participant in the Amazon Services LLC Associates Program, an affiliate program designed to provide a means for us to earn fees by linking to Amazon and affiliated sites.
Top