Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

nelly22

macrumors 6502
Original poster
Sep 29, 2009
366
5
What's the difference between delay, pause and return in idle handler?

Code:
on idle
     delay 60
end idle
 
Delay is a command that causes the script to wait for the specified number of seconds before continuing. The return statement exits a handler (with an optional value) and returns to the caller. In the case of the idle handler, the number returned becomes the rate (in seconds) that the handler is called (in a stay-open application, the idle handler is called repeatedly while the script is idle).
 
Delay is a command that causes the script to wait for the specified number of seconds before continuing. The return statement exits a handler (with an optional value) and returns to the caller. In the case of the idle handler, the number returned becomes the rate (in seconds) that the handler is called (in a stay-open application, the idle handler is called repeatedly while the script is idle).

Thanks.

Years ago in some forum people debated which is best.

What i should use if i want script to use CPU cycles as little as possible during idle.
 
You would want to use some kind of notification or timer so that your application sits idle until the system calls it - you don't want to poll using a repeat loop or a delay, since those will eat up cycles as well as block the user interface. The idle handler basically sets a timer, but you have access to most of the Cocoa API via AppleScriptObjC, so you can also use Cocoa timers and notifications.
 
You would want to use some kind of notification or timer so that your application sits idle until the system calls it - you don't want to poll using a repeat loop or a delay, since those will eat up cycles as well as block the user interface. The idle handler basically sets a timer, but you have access to most of the Cocoa API via AppleScriptObjC, so you can also use Cocoa timers and notifications.

Thanks.

These timers and notifications sounds cool, but i have no clue how to use these.

Is there anywhere total newbie friendly step by step instructions how to use these?
 
Last edited:
Is there anywhere total newbie friendly step by step instructions how to use these?

Until you get more familiar, I would just make a stay-open application and go with the idle handler. This handler is run after the main run handler completes, and repeats at intervals that you can change by returning a different number (the number of seconds until it fires again). It is basically a timer loop, but without all the Cocoa-y confusion. While your application is running, you can use the Activity Monitor to check out its cpu usage and tweak the timing accordingly.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.