Nautical bell: Difference between revisions

Content added Content deleted
(→‎{{header|AppleScript}}: Added 'idle' handler version.)
m (→‎{{header|AppleScript}}: Minor change to headings.)
Line 18: Line 18:
=={{header|AppleScript}}==
=={{header|AppleScript}}==


===repeat loop===
===Continuous repeat===


This version uses local time and speaks the bell rings using OS X's built-in speech synthesizer.
This version uses local time and speaks the bell rings using OS X's built-in speech synthesizer.
Line 38: Line 38:
end repeat</lang>
end repeat</lang>


===idle handler===
==='idle' handler===


For actions which are to be carried out at set intervals throughout the day, it's more usual to use a stay-open script applet with an 'idle' handler. When such an applet's launched, it sits there mostly doing nothing until it receives an 'idle' command from the system, whereupon it performs the actions in its 'idle' handler. If this handler returns a positive number (or something that can be interpreted as one), the system takes this as the number of seconds to wait before sending another 'idle' command to the applet. Otherwise the default is thirty seconds. This hogs the processor far less than having the script run on a continuous repeat. Unfortunately, depending on how busy the computer is at the time, 'idle' calls may be slightly delayed, so any time checks performed by the handler have to allow for this.
For actions which are to be carried out at set intervals throughout the day, it's more usual to use a stay-open script applet with an 'idle' handler. When such an applet's launched, it sits there mostly doing nothing until it receives an 'idle' command from the system, whereupon it performs the actions in its 'idle' handler. If this handler returns a positive number (or something that can be interpreted as one), the system takes this as the number of seconds to wait before sending another 'idle' command to the applet. Otherwise the default is thirty seconds. This hogs the processor far less than having the script run on a continuous repeat. Unfortunately, depending on how busy the computer is at the time, 'idle' calls may be slightly delayed, so any time checks performed by the handler have to allow for this.