Skip to Content
Beginning AppleScript®
book

Beginning AppleScript®

by Stephen G. Kochan
December 2004
Beginner
600 pages
13h 42m
English
Wrox
Content preview from Beginning AppleScript®

A.3. Chapter 3

A.3.1. Exercise 1 solution

-- Program to give a greeting

set today to current date
set weekdayToday to the weekday of today

if weekdayToday = Monday then
    set message to "Hope you had a great weekend!"
else if weekdayToday = Wednesday then
    set message to "Happy Hump Day!"
else if weekdayToday = Friday then
    set message to "TGIF!"
else if weekdayToday = Saturday or weekdayToday = Sunday then
    set message to "What are you doing here on the weekend?"
else
    set message to "Have a Great Day!"
end if

display dialog message with icon note buttons {"Thanks!"}

A.3.2. Exercise 2 solution

The steps to do this are outlined in the chapter.

A.3.3. Exercise 3 solution

true and true                 -- true
true and false                -- false
true or false                 -- true
false or false                -- false
not true and false            -- false
true and not false or true    -- true
true and not (false or true)  -- false

A.3.4. Exercise 4 solution

1986 - yes , 1989 - no , 2000 -- yes, 2010 -- no, 2100 - no

A.3.5. Exercise 5 solution

The null string becomes 0 when coerced into a number.

A.3.6. Exercise 6 solution

-- Speak salutation based on the time

set secsSinceMidnight to time of (current date)
set sixPM to time of date "6 PM"
set noon to time of date "12 PM"

if secsSinceMidnight < noon then
    say  "Good morning!"
else if secsSinceMidnight   noon and secsSinceMidnight < sixPM then
    say "Good afternoon!"
else
    say "Good evening!"
end if

A.3.7. Exercise 7 solution

-- Simple alarm clock program
-- sets an alarm a specified number of seconds in the ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Take Control of Your M-Series Mac

Take Control of Your M-Series Mac

Glenn Fleishman
What Successful Project Managers Do

What Successful Project Managers Do

W. Scott Cameron, Jeffrey S. Russell, Edward J. Hoffman, Alexander Laufer

Publisher Resources

ISBN: 9780764574009Purchase book