3.10. Exercises

  1. Modify the program from this chapter that displays various messages based on the weekday to also display the message "What are you doing here on the weekend" if it's a Saturday or Sunday.

  2. Using the result from the previous exercise, save your program as an application and then set it up to run every time you log in.

  3. Determine the results of the following expression evaluations. Then type them into Script Editor to verify your answers.

    true and true
    true and false
    true or false
    false or false
    not true and false
    true and not false or true
    true and not  (false or true)
  4. Run the leap year program presented in this chapter. Record whether the following years are reported as leap years: 1986, 1989, 2000, 2010, and 2100.

  5. Predict what would happen if you ran the following program and clicked OK without entering a value. Then run the program to verify your prediction. What can you say about the null string and its conversion to a number?

    display dialog "Pick a number between 1 and 10" default answer ""
    set guess to text returned of result as number
  6. Modify the salutation program from the "Creating Your First Application" section of this chapter. Use the technique described in the Note in that section, which explains how to calculate the seconds from midnight to noon and from midnight to 6 PM.

  7. The delay command pauses execution of your program for a specified number of seconds, as in

    delay 10

    which will pause your program for 10 seconds.

    Write a simple alarm clock program that asks ...

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.