5.9. Enhancing the Alarm Clock Program
Exercise 7 from Chapter 3 asked you to write a simple alarm clock program that would pause your application for a specified number of seconds before displaying a message. This exercise took advantage of the delay command, which pauses execution of your program for a specified number of seconds. Here's what your answer to that exercise might look like:
-- Simple alarm clock program -- sets an alarm a specified number of seconds in the future display dialog "Enter sleep time in seconds" default answer "60" set delayTime to text returned of result as number display dialog "Enter Message to Display" default answer "Your time is up!" set message to text returned of result -- pause execution for the specified number of seconds delay delayTime -- time is up; display the message display dialog message with icon note buttons {"Thanks!"} default button 1
This program works fairly well. However, the following points show you a couple of annoying things about it:
If the application isn't frontmost when the alarm goes off, it waits for you to click it before the dialog box is displayed
You have to specify the delay time in seconds. This is a nuisance if the amount of time you specify is lengthy, say, 90 minutes, or if you want to set the alarm for 6:45 PM for example, and it's now 3:03 PM.
You are going to make some enhancements to the program. In particular, you can extend this application so that it does the following:
Allows you to specify a time in ...
Get Beginning AppleScript® now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.