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.6. Chapter 6

A.6.1. Exercise 1 solution

-- Calculate the first 20 Fibonacci numbers

-- Define F1 and F2

set fibList to {0, 1}

-- Now calculate the next 18 numbers

repeat 18 times
    set end of fibList to (item −1 of fibList) + (item −2 of fibList)
end repeat

-- log the result

log fibList

A.6.2. Exercise 2 solution

set USCities to {{"Boston", 574000}, {"Chicago", 2784000}, {"Dallas", 1007000}, ¬
     {"Houston", 1631000}, {"Los Angeles", 3485000}, {"Philadelphia", 1586000}, ¬
     {"San Diego", 1111000}, {"San Francisco", 724000}, {"New York", 7323000}}

-- set the mix and max to the population of the first city

set min to item 2 of item 1 of USCities
set max to min
-- keep track of the list item that contains the max and min populations

set minIndex to 1
set maxIndex to 1

repeat with i from 2 to count USCities
    set population to item 2 of (item i of USCities)
    if population > max then
        set maxIndex to i
        set max to population
    end if

    if population < min then
        set minIndex to i
        set min to population
    end if
end repeat

display dialog "The city with the smallest population is " & item 1 of (item ¬
     minIndex of USCities) & return & "The city with the largest population is " ¬
     & item 1 of (item maxIndex of USCities)

A.6.3. Exercise 3 solution

set USCities to {¬ {name:"Boston", population:574000}, ¬ {name:"Chicago", population:2784000}, ¬ {name:"Dallas", population:1007000}, ¬ {name:"Houston", population:1631000}, ¬ {name:"Los Angeles", population:3485000}, ¬ {name:"Philadelphia", population:1586000}, ...
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