This is a text file consisting of the code examples (and the Appendix C URLs) from the second edition of the book, AppleScript: The Definitive Guide, by me (Matt Neuburg). Please don't use this file unless you've bought the book. Unless you really have to. For more information about the book: NOTE: This text file is encoded as MacRoman. Please adjust your browser or text processor accordingly. === page 8 === on open folderList repeat with aFolder in folderList if kind of (info for aFolder) is "Folder" then renameStuffIn(aFolder) end if end repeat end open on renameStuffIn(theFolder) set ix to 0 tell application "Finder" set folderName to name of theFolder set allItems to (get every item of theFolder) repeat with thisItem in allItems set ix to ix + 1 set newName to folderName & ix set name of thisItem to newName end repeat end tell end renameStuffIn === page 9 === set theProc to (get path to frontmost application as Unicode text) tell application "Finder" activate delay 1 -- give time for clip to convert from Classic set theURL to (get the clipboard as string) end tell ignoring application responses try open location theURL end try end ignoring activate application theProc === page 10a === set i to 1 tell application "iTunes" tell (get view of browser window 1) repeat with aTrack in (get every track) set track number of aTrack to i set i to i + 1 end repeat end tell end tell === page 10b === tell application "Microsoft Entourage" display dialog "Really delete selected messages completely?" set theMessages to current messages try delete theMessages delete theMessages end try end tell === page 12 ==== try tell application "http://www.boyzoid.com/comp/randomQuote.cfc" set returnValue to call soap {method name:"GetQuote", parameters:{HTMLformat:false}} end tell set L to |item| of returnValue repeat with anItem in L if |key| of anItem is "AUTHOR" then set auth to value of anItem end if if |key| of anItem is "QUOTE" then set quot to value of anItem end if end repeat set s to "-- " & return & quot & return & " -- " & auth on error what set s to "No signature today, sorry." end try tell application "Microsoft Entourage" set sig to signature id 1 set oldSig to (content of sig) set content of sig to s tell (make new draft window) set signature type to other set other signature choice to sig end tell set content of sig to oldSig end tell === page 21 === "set theAddress to \"" & fm address book::email & "\" tell application \"Mail\" tell (make new outgoing message) set visible to true make new to recipient at end of to recipients ¦ with properties {address:theAddress} end tell end tell" === page 27 === on awake from nib theObject tell application "Finder" set L to (get name of every disk) end tell set content of table view 1 of scroll view 1 of window 1 to L end awake from nib === page 28 === - (void) awakeFromNib { [self willChangeValueForKey:@"diskList"]; diskList = [[NSMutableArray alloc] init]; NSAppleScript* scpt = [[[NSAppleScript alloc] initWithSource: @"tell application \"Finder\"\r" "get name of disk 1\r" "end tell"] autorelease]; NSAppleEventDescriptor* result = [scpt executeAndReturnError: nil]; if ([result descriptorType] == 'utxt') [diskList addObject: [result stringValue]]; else if ([result descriptorType] == 'list') { int i, u = [result numberOfItems]; for (i=1; i<=u; i++) [diskList addObject: [[result descriptorAtIndex: i] stringValue]]; } [self didChangeValueForKey:@"diskList"]; } === page 29 === NSAppleScript* scpt = [[[NSAppleScript alloc] initWithContentsOfURL: [NSURL fileURLWithPath: [[NSBundle mainBundle] pathForResource: @"askFinder" ofType: @"scpt"]] error: nil] autorelease]; === page 30 === #!/usr/bin/perl $s = <click me === page 40 === % export AEDebugSends=1; export AEDebugReceives=1 === page 41a === % open /Applications/Safari.app === page 41b === % open http://www.apple.com === page 42 === % osascript -e 'tell app "Finder" to get disks' === page 51 === script myScript display dialog "Hello from " & (get my name) & "!" end script run myScript -- dialog says: Hello from myScript! === page 53 === sayHowdy( ) on sayHowdy( ) display dialog "Howdy" end sayHowdy === page 54 === tell app "Finder" to get ref disk 1 === page 55 === do shell script "echo 'hi'" password "myPassword" === page 64a === get disk 1 === page 64b === tell application "NoSuchApp" to get disk 1 === page 66 === tell application "Eudora" get subject of message 1 of mailbox "Trash" end tell === page 67a === tell application "Finder" get class euSu of class euMS 1 of class euMB "Trash" end tell === page 67b === if 1 = 2 then tell application "Eudora" get subject of message 1 of mailbox "Trash" end tell else display dialog "No problem!" end if === page 70 === tell application "BBEdit" activate make new text document end tell === page 79 === set name to "Matt" set feet to 7 set count to 9 set center to 1.5 === page 80a === tell 4 get it + 5 end tell === page 80b === 4 + 5 === page 81a === (define remvix (lambda (ix ls) (cond ((null? ls) '( )) ((= ix 1) (cdr ls)) (else (cons (car ls) (remvix (- ix 1) (cdr ls))))))) (remvix 2 '(mannie moe jack)) === page 81b === on remvix(ix, ls) if ls is {} then return {} else if ix is 1 then return rest of ls else return {item 1 of ls} & remvix(ix - 1, rest of ls) end if end remvix remvix(2, {"Mannie", "Moe", "Jack"}) === page 83a === set x to 1 copy x + 1 to y display dialog y === page 83b === set x to 1 copy (display dialog x) to y === page 84a === set pep to "Manny Moe Jack" === page 84b === set pep to "Manny" & return & "Moe" return pep === page 84c === set pep to "Manny\rMoe\nJack" === page 85a === set a to 1 === page 85b === set a to 1 set b to 2 === page 85c === set s to "one very long line " & "deserves another" === page 86a === 5 display dialog result -- 5 === page 86b === tell application "Finder" get the name of every folder end tell set L to the result === page 86c === tell application "Finder" count folders end tell set c to the result === page 86d === tell application "Finder" set L to (get the name of every folder) set c to count folders end tell === page 87a === set L to {"Mannie", "Moe"} set end of L to "Jack" === page 87b === on add(x, y) return x + y end add display dialog add(1, 2) === page 87c === on add(x, y) x + y end add display dialog add(1, 2) === page 88a === on add(x, y) x + y end add set z to add(1, 2) z === page 88b === on add(x, y) x + y end add set z to add(1, 2) return z === page 88c === set a to 1 -- this a comment on the same line as a command -- this a comment on a line by itself === page 89a === set a to 1 (* because we feel like it; tomorrow we may not feel like setting a to 1 *) (* in fact things could be very different tomorrow, but I really can't speak to that issue just now *) set b to 2 (* this seems a good idea too *) === page 89b === set a to (* because we feel like it *) 1 (* here's a good idea *) set a to 1 === page 89c === (* outer comment (* inner comment *) rest of outer comment *) === page 89d === (* "this works fine" and so does |this| *) === page 89e === (* set a to 7 *) === page 89f === --(* set a to 7 --*) === page 89g === (* set a to 1 -- and why not? *) === page 90 === a b a <= b a less than or equal b a is less than or equal to b a is not greater than b a isn't greater than b a does not come after b a doesn't come after b === page 91a === myHandler() on myHandler() repeat 3 times display dialog "Howdy" end repeat end myHandler === page 91b === tell application "Finder" if exists folder "Mannie" then reveal folder "Mannie" end if end tell === page 92a === tell application "Finder" to if exists folder "Mannie" then reveal folder "Mannie" end if === page 92b === local x repeat 1 times set x to 4 end repeat display dialog x === page 92c === set the x to the 9 display dialog the (get the the the the x + the 1) === page 96a === repeat 3 times on sayHowdy() display dialog "howdy" end sayHowdy end repeat -- compile-time error: Expected end but found on === page 96b === on outer() on sayHowdy() display dialog "howdy" end sayHowdy end outer -- compile-time error: Expected end but found on === page 96c === on outer() script s on sayHowdy() display dialog "howdy" end sayHowdy end script end outer === page 96d === on sayHowdy() display dialog "howdy" end sayHowdy sayHowdy() === page 97 === set x to 1 on outer() set xx to 1 script s set xxx to 1 on sayHowdy() display dialog "howdy" end sayHowdy set xxxx to 1 end script set xxxxx to 1 end outer set xxxxxx to 1 === page 98 === on run display dialog "howdy" end run display dialog "howdy" === page 99a === on run display dialog "howdy" end run on sayHowdy() display dialog "hello" end sayHowdy script s display dialog "bonjour" end script === page 99b === on sayHowdy() display dialog "howdy" end sayHowdy === page 99c === on run on sayHowdy() display dialog "howdy" end sayHowdy end run -- compile-time error: Expected end but found on === page 99d === set x to 1 on sayHowdy() display dialog "howdy" end sayHowdy set x to 2 === page 102a === set L to {1, 2, 3} set LL to L -- set by reference set end of L to 4 -- mutate a list in place LL -- {1, 2, 3, 4}, because it is the same list as L === page 102b === set {x, y, z} to {1, 2, 3} z -- 3, and can you guess what x and y are? === page 103a === set x to x + 1 === page 103b === set x to 5 x === page 104a === set x to 5 set x to x + 1 === page 104b === script s display dialog "howdy" end script === page 105a === set x to 5 set x to 5.2 set x to "hello" set x to string set x to {"fee", "fie", "fo", "fum"} set x to (path to current user folder) === page 105b === set myVar to 5 set myvar to myvar + 1 === page 107a === set |1| to 2 if |1| is 2 then display dialog "The laws of logic are suspended." end if === page 107b === set |monZro| to 0 === page 107c === set |my big long variable name with spaces| to 7 === page 107d === set |MyVar| to 5 set |MyVar| to |Myvar| + 1 -- error === page 108 === set |is| to "ought" === page 109 === script s display dialog "howdy" end script === page 110a === script s display dialog "howdy" end script run s -- howdy === page 110b === script s display dialog "howdy" end script tell s run -- howdy end tell === page 110c === script s display dialog "howdy" end script tell s to run -- howdy === page 110d === script myScript end script run myScript -- error: stack overflow === page 111a === script s property x : 5 end script === page 111b === script s property x : 10 display dialog x -- 10 set x to 5 display dialog x -- 5 end script === page 111c === property x : 5 display dialog x === page 111d === property L : {1, 2, 3} script s property LL : L set end of LL to 4 end script run s L -- {1, 2, 3, 4} === page 112a === script myScript display dialog "Howdy" end script set x to myScript run x -- Howdy === page 112b === script myScript display dialog "Howdy" end script set myScript to 9 display dialog myScript -- 9 === page 112c === script sayHowdy display dialog "Howdy" end script script sayGetLost display dialog "Get Lost" end script set sayHowdy to sayGetLost run sayHowdy -- Get Lost === page 112d === script sayHello property greeting : "Hello" display dialog greeting set greeting to "Get Lost" end script set x to sayHello run sayHello -- Hello run x -- Get Lost === page 113 === script myScript property x : "Howdy" on sayHowdy( ) display dialog x end sayHowdy script innerScript display dialog x end script end script set x of myScript to "Hello" myScript's sayHowdy( ) -- Hello run innerScript of myScript -- Hello === page 114a === script myScript property x : "Howdy" on sayHowdy( ) display dialog x end sayHowdy script innerScript display dialog x end script end script tell myScript set its x to "Hello" sayHowdy( ) -- Hello run its innerScript -- Hello end tell === page 114b === script myScript property x : 5 end script tell myScript set its x to (its x) + 1 end tell display dialog myScript's x === page 115a === property x : 5 set x to x + 1 display dialog x === page 115b === script outerScript script innerScript property x : 5 on increment( ) set x to x + 1 end increment end script tell innerScript to increment( ) display dialog innerScript's x end script run outerScript -- 6, then 7, and so forth === page 116a === script myScript script myInnerScript display dialog "Hello" end script run myInnerScript end script script myNastyScript display dialog "Get lost" end script run myScript set myScript's myInnerScript to myNastyScript === page 116b === repeat 3 times script s property x : 1 display dialog x set x to x + 1 end script run s end repeat === page 117a === script myScript on run script myInnerScript property x : 10 end script tell myInnerScript set its x to (its x) + 1 display dialog its x end tell end run end script run myScript -- 11 === page 117b === property x : 5 set x to x + 1 display dialog x === page 118 === property x : 5 set x to x + 1 try display dialog x on error return 0 end try === page 120 === set thePath to (path to desktop as string) & "myPrefs.scpt" script myPrefs property favoriteColor : "" end script try set myPrefs to load script file thePath on error set favoriteColor of myPrefs to text returned of (display dialog "Favorite Color:" default answer "" buttons {"OK"} default button "OK") store script myPrefs in file thePath replacing yes end try display dialog "Your favorite color is " & favoriteColor of myPrefs === page 121 === -- load the library . . . set f to (path to desktop as string) & "library.scpt" set lib to load script alias f -- . . . and use it set L to {"Mannie", "Moe", "Jack"} set L2 to lib's remvix(2, L) L2 -- {"Mannie", "Jack"} === page 122 === -- load the library . . . property f : (path to desktop as string) & "library.scpt" property lib : load script alias f -- . . . and use it set L to {"Mannie", "Moe", "Jack"} set L2 to lib's remvix(2, L) L2 -- {"Mannie", "Jack"} === page 123a === script mommy on talk( ) display dialog "How do you do?" end talk end script script baby property parent : mommy end script baby's talk( ) -- How do you do? === page 123b === script mommy on talk( ) display dialog "How do you do?" end talk end script script baby property parent : mommy talk( ) end script run baby -- How do you do? === page 124a === script mommy property address : "123 Main Street" end script script baby property parent : mommy end script display dialog baby's address -- 123 Main Street set baby's address to "234 Chestnut Street" display dialog mommy's address -- 234 Chestnut Street === page 124b === script mommy property address : "123 Main Street" end script script baby property parent : mommy on tellAddress( ) display dialog my address end tellAddress end script baby's tellAddress( ) -- 123 Main Street === page 124c === script mommy script talk display dialog "How do you do?" end script end script script baby property parent : mommy end script run baby's talk -- How do you do? === page 124d === script mommy script talk display dialog "How do you do?" end script end script script baby property parent : mommy run my talk end script run baby -- How do you do? === page 125a === script mommy on talk() display dialog "How do you do?" end talk end script script baby property parent : mommy talk() end script run baby -- How do you do? === page 125b === script mommy on tellWeight( ) display dialog my weight end tellWeight end script script baby property parent : mommy property weight : "9 pounds" end script baby's tellWeight( ) -- 9 pounds === page 126a === script mommy property weight : "120 pounds" on tellWeight( ) display dialog my weight end tellWeight end script script baby property parent : mommy property weight : "9 pounds" end script script baby2 property parent : mommy property weight : "8 pounds" end script mommy's tellWeight( ) -- 120 pounds baby's tellWeight( ) -- 9 pounds baby2's tellWeight( ) -- 8 pounds === page 126b === script mommy on cry() display dialog "Boo-hoo, sniff sniff..." end cry on beSad() cry() end beSad end script script baby property parent : mommy on cry() display dialog "Waaaaaaa!" end cry end script baby's beSad() -- Waaaaaaa! === page 127a === script mommy property weight : "120 pounds" on tellWeight( ) display dialog my weight end tellWeight end script script baby property parent : mommy property weight : "9 pounds" parent's tellWeight( ) -- no polymorphism continue tellWeight( ) -- polymorphism end script run baby -- 120 pounds, 9 pounds === page 127b === script myScript script myInnerScript my parent -- the top-level script, not myScript end script run myInnerScript end script run myScript === page 127c === script myScript script myInnerScript property parent: myScript -- compile-time error end script end script === page 128a === property x : 10 script outer property x : 20 script inner end script end script get outer's inner's x -- 10 === page 128b === on sayHowdy() display dialog "Howdy" end sayHowdy script s end script tell s to sayHowdy() -- Howdy === page 128c === on sayHowdy() display dialog "Howdy" end sayHowdy script s property parent : 3 end script tell s to sayHowdy() -- Error: Cant get sayHowdy of 3 === page 128d === property x : 5 script myScript property x : 10 display dialog x end script run myScript -- 10 === page 129a === property x : 5 script myScript property x : 10 display dialog my parent's x end script run myScript -- 5 === page 129b === property topLevel : me property x : 5 script scriptOne property x : 10 end script script scriptTwo property x : 20 property parent : scriptOne display dialog topLevel's x end script run scriptTwo -- 5 === page 129c === set pi to 3 display dialog pi -- 3 display dialog AppleScript's pi -- 3.141592... display dialog parent's pi -- 3.141592... === page 129d === display dialog (get name of current application) -- Script Editor === page 130a === script myScript my parent -- script, the anonymous top level my parent's parent -- script AppleScript my parent's parent's parent -- current application end script run myScript === page 130b === script s property parent : {"Mannie", "Moe", "Jack"} on greeting() return "Howdy" end greeting end script tell s greeting() -- "Howdy" get item 2 -- "Moe" end tell === page 130c === script s property parent : {"Mannie", "Moe", "Jack"} end script get s & "Pep" -- {script s, "Pep"}, not {"Mannie", "Moe", "Jack", "Pep"} === page 130d === script s property p : 10 end script tell s get p end tell === page 131a === script s on h() return 10 end h end script tell s get h end tell === page 131b === script s on h() return 10 end h end script tell s h() -- 10 end tell === page 131c === script x property greeting : "Howdy" on myHandler() display dialog greeting end myHandler script y display dialog greeting myHandler() end script end script run x's y -- Howdy, then error: script y doesnt understand the myHandler message === page 132a === script x property greeting : "Howdy" on myHandler() display dialog greeting end myHandler script y x's myHandler() -- explicit target end script end script run x's y -- Howdy === page 132b === script s end script tell s to count -- 0 === page 132c === script theCount on count return "1, 2, 3, ha ha ha" end count end script tell theCount to count -- "1, 2, 3, ha ha ha" === page 132d === script s property parent : {"Mannie", "Moe", "Jack"} end script tell s to count -- 3 === page 133 === tell application "Finder" sayHowdy() -- Finder got an error: Cant continue sayHowdy. end tell === page 134 === on sayHowdy() display dialog "howdy" end sayHowdy === page 135a === on sayHowdy() display dialog "howdy" end sayHowdy sayHowdy() === page 135b === on getRam( ) set bytes to system attribute "ram " return bytes div (2 ^ 20) end getRam === page 136a === on getRam( ) set bytes to system attribute "ram " return bytes div (2 ^ 20) end getRam display dialog "You have " & getRam( ) & "MB of RAM. Wow!" === page 136b === on noValue( ) return end noValue set x to noValue( ) === page 136c === on noValue( ) return end noValue set x to 1 set x to noValue( ) set x to x + 1 -- error: The variable x is not defined === page 137a === on getRam( ) set bytes to system attribute "ram " return bytes div (2 ^ 20) end getRam set s to "You have " & getRam( ) & "MB of RAM. Wow! " set s to s & getRam( ) & "MB is a lot!" display dialog s === page 137b === on getRam( ) set bytes to system attribute "ram " return bytes div (2 ^ 20) end getRam set myRam to getRam( ) set s to "You have " & myRam & "MB of RAM. Wow! " set s to s & myRam & "MB is a lot!" display dialog s === page 138a === on sayHowdy( ) display dialog "Howdy" end sayHowdy set sayHello to sayHowdy sayHello( ) -- Howdy === page 138b === on sayHowdy( ) display dialog "Howdy" end sayHowdy set sayHowdy to 9 display dialog sayHowdy -- 9 === page 138c === on sayHowdy( ) display dialog "Howdy" end sayHowdy on sayGetLost( ) display dialog "Get Lost" end sayGetLost set sayHello to sayGetLost sayHello( ) -- Get Lost === page 139a === on sayHello() display dialog "Hello" end sayHello on sayGetLost() display dialog "Get Lost" end sayGetLost set L to {sayHello, sayGetLost} -- for this example, we decide randomly which one to call set h to item (random number from 1 to 2) of L h() === page 139b === on subtract(x, y) return x - y end subtract subtract(3, 2) -- 1 === page 139c === on subtract(x, y) return x - y end subtract set x to 2 set y to 3 subtract(y, x) -- 1 === page 140a === on extend(LL) set end of LL to "Jack" end extend set L to {"Mannie", "Moe"} extend(L) L -- {"Mannie", "Moe", "Jack"} === page 140b === script myScript property x : 10 end script on myHandler(s) set s's x to 20 end myHandler myHandler(myScript) display dialog myScript's x -- 20 === page 141a === on byValue(x) copy x to y return y end byValue on extend(LL) set end of LL to "Jack" end extend set L to {"Mannie", "Moe"} extend(byValue(L)) L -- {"Mannie", "Moe"} === page 141b === on greet(what) display dialog what end greet greet() -- error: {} doesnt match the parameters {what} for greet === page 142a === on area(L) set a to item 1 of L if (count L) = 2 then set b to item 2 of L else set b to item 1 of L end if return a * b end area area({3, 4}) -- 12 area({3}) -- 9 === page 142b === on greet(R) set defaults to {greeting:"Hello", whom:"World"} set R to R & defaults display dialog R's greeting & ", " & R's whom & "!" end greet greet({whom:"Everybody"}) -- Hello, Everybody! greet({greeting:"Howdy"}) -- Howdy, World! greet({greeting:"Bonjour", whom:"Monde"}) -- Bonjour, Monde! greet({}) -- Hello, World! === page 142c === person given firstName:"Matt", lastName:"Neuburg", age:51, place:"Ojai" on person given firstName:fir, lastName:las display dialog fir & space & las end person === page 144a === on firstLetter from aWord return character 1 of aWord end firstLetter display dialog (firstLetter from "hello") on sum of x beside y return x + y end sum display dialog (sum of 1 beside 2) on stopping by woods on aSnowyEvening return woods & aSnowyEvening end stopping display dialog (stopping on "horse" by "farm") === page 144b === on stopping by woods on aSnowyEvening if woods and aSnowyEvening then return "lovely, dark and deep" else return "ugly and shallow" end if end stopping display dialog (stopping with on and by) display dialog (stopping with by without on) === page 145 === on sum of L beside dummy set total to 0 repeat with aNumber in L set total to total + aNumber end repeat return total end sum sum(1, 2, 3, 4, 5, 6, 7) -- 28 === page 146 === on sum given theOne:x, theOther:y return x + y end sum display dialog (sum given theOther:2, theOne:3) on scout given loyal:loyal, trustworthy:trustworthy if loyal and trustworthy then return "eagle" else return "sparrow" end if end scout display dialog (scout with loyal and trustworthy) on area of side1 beside side2 given measure:m return ((side1 * side2) as string) & space & m end area area of 4 beside 5 given measure:"inches" -- "20 inches" === page 147 === on adding folder items to ff after receiving L display dialog ff & space & L end adding folder items to adding folder items to "howdy" after receiving "there" === page 148 === script s on run {what, what2} display dialog what & space & what2 end run end script run s -- error: script s doesnt match the parameters {what, what2} for run run script s with parameters {"howdy", "there"} === page 149 === property args : null script s on run {what, what2} display dialog what & space & what2 end run end script script trampoline property parent : s continue run args end script set args to {"howdy", "there"} run trampoline === page 150a === on filter(L) if L = {} then return L if {class of item 1 of L} is in {real, integer, number} then return {item 1 of L} & filter(rest of L) else return filter(rest of L) end if end filter filter({"hey", 1, "ho", 2, 3}) -- {1, 2, 3} === page 150b === on remvix(L, ix) if L is {} then return {} if ix is 1 then return rest of L else return item 1 of L & remvix(rest of L, ix - 1) end if end remvix set L to {} set max to 505 repeat with x from 1 to max set end of L to x end repeat remvix(L, max) === page 150c === script s on filter(L) if L = {} then return L if {class of item 1 of L} is in {real, integer, number} then return {item 1 of L} & filter(rest of L) else return filter(rest of L) end if end filter end script set f to s's filter f({"hey", 1, "ho", 2, 3}) -- error: script doesnt understand the filter message === page 151a === on sayHowdy( ) display dialog "Howdy" end sayHowdy on doThis(what) what( ) end doThis doThis(sayHowdy) -- error: script doesnt understand the what message === page 151b === on sayHowdy() display dialog "Howdy" end sayHowdy on doThis(what) global what2 set what2 to what what2() end doThis doThis(sayHowdy) -- Howdy === page 151c === script sayHowdy display dialog "Howdy" end script on doThis(what) run what end doThis doThis(sayHowdy) -- Howdy === page 152a === script myScript on doAnything( ) end doAnything doAnything( ) end script on doThis(what) run what end doThis on sayHowdy( ) display dialog "Howdy" end sayHowdy set myScript's doAnything to sayHowdy doThis(myScript) -- Howdy === page 152b === on sayHowdy( ) display dialog "Howdy" end sayHowdy on doThis(what) script whatToDo property theHandler : what theHandler( ) end script run whatToDo end doThis doThis(sayHowdy) -- Howdy === page 153a === on filter(L, crit) script filterer property criterion : crit on filter(L) if L = {} then return L if criterion(item 1 of L) then return {item 1 of L} & filter(rest of L) else return filter(rest of L) end if end filter end script return filterer's filter(L) end filter on isNumber(x) return ({class of x} is in {real, integer, number}) end isNumber filter({"hey", 1, "ho", 2, 3}, isNumber) === page 153b === on makeHandler( ) script x on greet( ) display dialog "Howdy" end greet end script return x's greet end makeHandler set y to makeHandler( ) y( ) -- Howdy === page 153c === on scriptMaker( ) script myScript property x : "Howdy" display dialog x end script return myScript end scriptMaker set s to scriptMaker( ) run s -- Howdy === page 154a === on scriptMaker(what) script myScript property x : what display dialog x end script return myScript end scriptMaker set s to scriptMaker("Hello") run s -- Hello === page 154b === on makeFilterer(crit) script filterer property criterion : crit on filter (L) if L = {} then return L if criterion(item 1 of L) then return {item 1 of L} & (filter (rest of L)) else return filter (rest of L) end if end filter end script return filterer end makeFilterer on isNumber(x) return ({class of x} is in {real, integer, number}) end isNumber on isText(x) return ({class of x} is in {string, text, Unicode text}) end isText set numbersOnly to makeFilterer(isNumber) set textOnly to makeFilterer(isText) tell numbersOnly filter ({"hey", 1, "ho", 2, "ha", 3}) -- {1, 2, 3} filter ({"Mannie", 7, "Moe", 8, "Jack", 9}) -- {7, 8, 9} end tell tell textOnly filter ({"hey", 1, "ho", 2, "ha", 3}) -- {"hey", "ho", "ha"} filter ({"Mannie", 7, "Moe", 8, "Jack", 9}) -- {"Mannie", "Moe", "Jack"} end tell === page 155 === on newCounter( ) script aCounter property c : 0 on increment( ) set c to c + 1 end increment end script return aCounter end newCounter -- and heres how to use it set counter1 to newCounter( ) counter1's increment( ) counter1's increment( ) counter1's increment( ) set counter2 to newCounter( ) counter2's increment( ) counter1's increment( ) display dialog counter1's c -- 4 display dialog counter2's c -- 1 === page 158a === property x : 10 script myScript display dialog x end script on myHandler( ) display dialog x end myHandler run myScript -- 10 myHandler( ) -- 10 === page 158b === property x : 5 script scriptOne property x : 10 script scriptTwo property x : 20 display dialog x end script display dialog x run scriptTwo end script script scriptThree property x : 30 display dialog x end script script scriptFour display dialog x end script display dialog x -- 5 run scriptOne -- 10, 20 run scriptThree -- 30 run scriptFour -- 5 === page 159a === script scriptOne property x : 10 script inner property x : 20 display dialog scriptOne's x -- 10 end script end script script scriptTwo display dialog scriptOne's x -- 10 display dialog x -- error: The variable x is not defined end script run scriptOne's inner run scriptTwo === page 159b === run myScript -- Howdy script myScript display dialog "Howdy" end script === page 159c === myHandler() -- Howdy on myHandler() display dialog "Howdy" end myHandler === page 159d === display dialog x -- Howdy property x : "Howdy" === page 160a === run myScript script myScript display dialog myOtherScript's x -- error: The variable myOtherScript is not defined end script script myOtherScript property x : "Howdy" end script === page 160b === run myScript script myScript myHandler() end script on myHandler() display dialog "Howdy" end myHandler === page 160c === run myScript script myScript myHandler -- error: The variable myHandler is not defined end script on myHandler() display dialog "Howdy" end myHandler === page 160d === on myHandler( ) run myScript script myScript -- compile-time error: The myScript property is specified more than once display dialog "Howdy" end script end myHandler myHandler( ) === page 161a === local x set x to 5 script myScript display dialog x -- error: The variable x is not defined end script run myScript === page 161b === property x : 5 script myScript local x display dialog x -- error: The variable x is not defined end script run myScript === page 162a === property x : 5 script myScript local x on myHandler( ) set x to 10 end myHandler myHandler( ) set x to 20 end script run myScript display dialog x -- 10 (not 20) === page 162b === on myHandler(what) local x set x to 7 end myHandler myHandler("howdy") display dialog what -- error: The variable what is not defined display dialog x -- error: The variable x is not defined === page 162c === on myHandler() local x set x to 5 script myScript on h() display dialog x end h h() end script run myScript end myHandler myHandler() -- 5 === page 163a === on h() script s display dialog "howdy" end script script ss run s end script run ss end h h() -- howdy === page 163b === global x set x to 5 on myHandler( ) display dialog x end myHandler myHandler( ) -- 5 === page 163c === set x to 5 on myHandler() display dialog x end myHandler global x set x to 10 myHandler() -- error: The variable x is not defined === page 164a === on setX( ) global x set x to 5 end setX on getX( ) global x display dialog x end getX setX( ) getX( ) -- 5 === page 164b === on setX() global x set x to 5 end setX setX() display dialog x -- 5 === page 164c === on setX() global x set x to 5 end setX on getX() display dialog x end getX setX() getX() -- error: The variable x is not defined === page 165a === on incrementOrReport(report) global ct if report then return ct try set ct to ct + 1 on error set ct to 1 end try end incrementOrReport incrementOrReport(false) incrementOrReport(false) incrementOrReport(false) incrementOrReport(true) -- 3 === page 165b === on setX() global x try set x to x + 1 on error set x to 5 end try end setX on getX() global x display dialog x end getX setX() getX() -- 5, then 6, and so on === page 166a === on setX() global x set x to x + 1 end setX on getX() global x display dialog x end getX setX() getX() -- 6, then 7, and so on property x : 5 === page 166b === global topLevel, x set topLevel to me set x to 5 script s property x : 10 display dialog topLevel's x end script run s -- 5 === page 166c === global x set x to 10 script outer property x : 20 script inner global x display dialog x end script end script run outer's inner -- 10 === page 167a === script myScript global x on myHandler( ) set x to 5 end myHandler myHandler( ) end script on getX( ) global x display dialog x end run myScript getX( ) -- 5 === page 167b === set x to 5 on getX() global x display dialog x end getX getX() -- 5 === page 168a === on run set howdy to "Howdy" sayHowdy( ) -- Howdy end run on sayHowdy( ) global howdy display dialog howdy end sayHowdy === page 168b === set x to 5 on getX() set x to 10 display dialog x end getX getX() -- 10 display dialog x -- 5 === page 168c === script s set x to 10 on myHandler() display dialog x end myHandler myHandler() end script run s -- error: The variable x is not defined === page 169 === on getX() set x to 10 script s display dialog x end script run s end getX getX() -- 10 === page 170 === if 1 is 2 then local x end if set x to 7 on myHandler() global x display dialog x end myHandler myHandler() -- error: The variable x is not defined === page 171 === global x set x to 5 on myHandler() display dialog x -- x is a free variable end myHandler set x to 10 myHandler() -- 10 (not 5) === page 172a === property x : 5 script myScript display dialog x -- x is a free variable end script script myOtherScript set x to 20 -- x is a free variable run myScript -- myScript is a free variable end script set x to 10 run myScript -- 10 run myOtherScript -- 20 === page 172b === set x to 5 local x -- compile-time error: Cant declare x as both a local and global variable === page 172c === on getX( ) display dialog x global x -- compile-time error: Cant declare x as both a local and global variable end getX === page 172d === on myHandler(what) global what -- compile-time error: Cant declare x as both a local and global variable end === page 173a === on getX( ) global x local x -- compile-time error: Cant declare x as both a local and global variable end getX === page 173b === on getX( ) local x global x -- compile-time error: Cant declare x as both a local and global variable end getX === page 173c === local x global x set x to 5 on setX( ) set x to 10 end setX on getX( ) display dialog x end getX setX( ) getX( ) -- 10 display dialog x -- 5 === page 173d === global x set x to 5 local x on getX( ) display dialog x end getX getX( ) -- 5 display dialog x -- error: The variable x is not defined === page 174a === global x set x to 5 local x set x to 10 x -- 10 my x -- 5 === page 174b === global x set x to 10 repeat with x from 1 to 5 end repeat x -- 5 my x -- 10 === page 174c === script myScript property x : 4 display dialog x local x display dialog x end script run myScript -- 4, then error: The variable x is not defined === page 174d === script myScript property x : 10 local x set x to 20 on myHandler( ) display dialog x end myHandler myHandler( ) display dialog x end script run myScript -- 10, then 20 === page 174e === property x: 10 global x -- compile-time error: Cant declare x as both a local and global variable === page 175a === global x set x to 10 script myScript global x set x to 5 property x : 20 display dialog x end script run myScript -- 5 display dialog x -- 10 === page 175b === property x : 5 script myScript display dialog x end script set x to 20 set dummy to myScript set x to 10 run myScript -- 20 === page 176 === property x : 5 on h() script myScript display dialog x end script return myScript end h set x to 10 set s to h() run s -- 10 set x to 20 run s -- 10 set x to 30 run s -- 10 === page 177a === on h() local x set x to "howdy" script myScript display dialog x end script return myScript end h set s to h() run s -- howdy === page 177b === on scriptMaker(what) script myScript display dialog what end script return myScript end scriptMaker set s to scriptMaker("Hello") run s -- Hello === page 178a === set f to (path to desktop as string) & "myScript.scpt" global greeting set greeting to "Howdy" property farewell : "Byebye" script s display dialog greeting display dialog farewell end script store script s in file f replacing yes === page 178b === set f to (path to desktop as string) & "myScript.scpt" run script alias f -- Howdy, then Byebye === page 179a === set f to (path to desktop as string) & "myScript.scpt" set s to load script alias f global greeting set greeting to "Bonjour" property farewell : "Au revoir" run s -- Bonjour, then Byebye === page 179b === set f to (path to desktop as string) & "myScript.scpt" set s to load script alias f set greeting to "Bonjour" property farewell : "Au revoir" run s -- Bonjour, then Byebye === page 179c === set f to (path to desktop as string) & "myScript.scpt" script s global greeting display dialog greeting end script store script s in file f replacing yes === page 179d === set f to (path to desktop as string) & "myScript.scpt" set greeting to "Howdy" run (load script alias f) -- Howdy === page 184 === script s on count return "1, 2, 3, ha ha ha" end count end script count s -- "1, 2, 3, ha ha ha" count "hello" -- 5 count {1, 2, 3} -- 3 count application "Finder" -- 32 (the number of desktop items) === page 188a === set x to "howdy" tell application "Finder" count x end tell === page 188b === set newname to "someFolder" tell application "Finder" set oldname to name of folder 1 set name of folder 1 to newname end tell display dialog oldname === page 189a === on whatNumber( ) return 1 end whatNumber tell application "Finder" get folder whatNumber( ) -- error: Finder got an error: Cant continue whatNumber end tell === page 189b === tell application "iTunes" tell application "Finder" count folders end tell end tell === page 189c === count folders of application "Finder" of application "iTunes" === page 189d === tell application "Finder" count "howdy" end tell === page 190a === tell application "Finder" name of folder 1 end tell === page 190b === tell application "Finder" to name of folder 1 === page 190c === tell application "Finder" to display dialog (name of folder 1) -- error: Finder got an error: Cant make name of folder 1 into type string === page 190d === tell application "Finder" to display dialog (get name of folder 1) -- Mannie === page 190e === tell application "TextEdit" to delete word 1 of document 1 === page 191a === tell application "TextEdit" to delete (get word 1 of document 1) === page 191b === tell 7 to get -- compile-time error: Expected expression but found end of script === page 191c === tell application "Finder" tell folders it -- every folder of application "Finder" end tell end tell === page 191d === tell application "Finder" tell folder 1 open file 1 open it end tell end tell === page 192a === set home to "Ojai" tell application "Finder" get home -- folder "mattneub" of folder "Users"... end tell === page 192b === tell application "Finder" tell folder 1 get container -- container, a class end tell end tell === page 192c === tell application "Finder" tell folder 1 get its container -- folder "Desktop" of... end tell get container of folder 1 -- folder "Desktop" of... end tell === page 192d === tell application "Microsoft Word" tell find object of selection set content to "o" tell replacement set content to "a" end tell execute find replace replace all end tell end tell === page 193a === tell application "Microsoft Word" tell (get find object of its selection) set its content to "o" tell (get its replacement) set its content to "a" end tell execute find replace replace all end tell end tell === page 193b === script myScript me -- script myScript end script run myScript me -- script, the anonymous top-level script parent of me -- script AppleScript === page 193c === on reverseString(s) set text item delimiters to "" return (reverse of characters of s) as string end reverseString tell application "Finder" set name of folder 1 to reverseString(get name of folder 1) -- error: Finder got an error: Cant continue reverseString end tell === page 194a === set home to "Ojai" tell application "Finder" get my home -- error: Cant make home directory into type reference end tell === page 194b === set home to "Ojai" tell application "Finder" get |home| -- "Ojai" end tell === page 194c === on reveal(what) display dialog (get name of what) end reveal tell application "Finder" reveal(file 1) -- the Finder highlights the files icon end tell === page 194d === on reveal(what) display dialog (get name of what) end reveal tell application "Finder" my reveal (file 1) -- error: Expected expression but found command name end tell === page 195a === on reveal(what) display dialog (get name of what) end reveal tell application "Finder" |reveal|(file 1) -- error: Finder got an error: Cant continue reveal end tell === page 195b === on reveal(what) display dialog (get name of what) end reveal tell application "Finder" my |reveal|(file 1) end tell === page 196a === tell application "Finder" get startup disk set startup disk to disk "gromit" -- error: Finder got an error: Cant set startup disk to disk gromit end tell === page 196b === tell application "Finder" set s to name of disk 1 set s to "yoho" end tell === page 196c === tell application "Finder" set d to disk of folder 1 end tell d -- startup disk of application "Finder" === page 196d === tell application "Finder" set d to disk of folder 1 end tell get name of d -- "feathers" === page 197a === tell application "Finder" set d to disk of folder 1 end tell set name of d to "yoho" -- Dont say this unless you mean it! === page 197b === get version of application "Finder" -- 10.4.2 === page 199 === get words 1 thru 4 of "now is the winter of our discontent" get words beginning thru 4 of "now is the winter of our discontent" get words from character 12 to character 17 of "now is the winter" get words from character 12 to character -1 of "now is the winter" get words from character 12 to end of "now is the winter" get words 1 to 3 of "now is the winter of our discontent" -- compile-time error === page 200a === tell application "TextEdit" tell document 1 get word after word 1 end tell end tell === page 200b === tell application "BBEdit" tell text of window 1 get insertion point before word 4 end tell end tell === page 200c === tell application "BBEdit" tell text of window 1 set pt to insertion point before word 4 set contents of pt to "great " end tell end tell === page 200d === tell application "TextEdit" tell text of document 1 make new word at after word 2 with data "not " -- changes this is a test to this is not a test end tell end tell tell application "TextEdit" tell text of document 1 duplicate word 1 to end -- changes fair is foul and foul is to fair is foul and foul is fair end tell end tell tell application "TextEdit" tell text of document 1 duplicate word 1 to beginning of word 3 -- changes wonder of s to wonder of wonders end tell end tell tell application "TextEdit" tell text of document 1 duplicate word 1 to word 7 -- changes fair is foul and foul is foul to fair is foul and foul is fair end tell end tell tell application "Script Debugger" move window 2 to beginning -- bring the second window frontmost end tell === page 202a === tell application "Finder" to get files where name begins with "s" tell application "Finder" to get every file where name begins with "s" tell application "Finder" to get files where name of it begins with "s" tell application "Finder" to get files where its name begins with "s" tell application "Finder" to get files whose name begins with "s" === page 202b === tell application "System Events" get process 1 whose frontmost is true get process 1 where it is frontmost end tell === page 202c === tell application "Microsoft Entourage" get every POP account whose email address contains "matt" -- {} end tell === page 202d === tell application "Microsoft Entourage" get every POP account whose its email address contains "matt" -- {POP account id 1...} end tell === page 202e === tell application "TextEdit" tell text of document 1 get every word where it contains "t" get words whose it contains "t" end tell end tell === page 203a === tell application "BBEdit" tell text 1 of window 1 get every word whose contents contains "t" end tell end tell === page 203b === tell application "BBEdit" tell text 1 of window 1 get word 1 whose contents contains "t" end tell end tell === page 203c === tell application "TextEdit" tell document 1 words where it begins with "t" and it ends with "t" -- {"test"} end tell end tell === page 203d === tell application "Finder" get every disk whose name begins with "g" -- "gromit" end tell set pepBoys to {"Mannie", "Moe", "Jack"} tell pepBoys get every item whose text begins with "M" -- error: Cant get... end tell === page 204a === tell application "Finder" to get name of every disk === page 204b === tell application "iTunes" tell view of browser window 1 get name of every track end tell end tell === page 204c === tell application "iTunes" tell view of browser window 1 get database ID of every track whose name contains "Palestrina" end tell end tell === page 204d === tell application "Finder" get file 1 of every folder end tell === page 204e === tell application "Address Book" get every email of every person end tell === page 204f === tell application "Finder" get every file of every folder end tell === page 205a === tell application "Microsoft Entourage" move (every message of in box folder where address of its sender contains "lambert") to folder "temp" end tell === page 205b === tell application "BBEdit" contents of every word of window 1 -- {"this", "is", "a", "test"} end tell === page 205c === tell application "BBEdit" length of every word of window 1 -- 4 end tell === page 205d === tell application "BBEdit" tell document 1 set L to get contents of every word set L2 to {} repeat with aWord in L set end of L2 to length of aWord end repeat end tell end tell === page 206a === set {x, y, z} to {1, 2, 3} === page 206b === tell application "Finder" set {x, y} to {name, comment} of folder 1 end tell {x, y} -- {"Mannie", "howdy"} === page 206c === tell application "Finder" tell folder "Mannie" set {comment, name} to {"zowie", "Jack"} end tell end tell === page 206d === tell application "Finder" tell folder "Mannie" set {name, comment} to {"Jack", "zowie"} -- error end tell end tell === page 209a === tell application "Finder" set x to (get folder 1) end tell === page 209b === tell application "Finder" set x to (get folder 1) display dialog (get name of x) -- Mannie end tell === page 210a === tell application "Finder" set x to (get folder 1) end tell name of x -- "Mannie" === page 211a === tell application "Finder" set x to folder 1 display dialog (get name of x) -- Mannie set name of x to "Moe" display dialog (get name of x) -- error! end tell === page 211b === set x to 100 set y to a reference to x === page 211c === tell application "Finder" set x to a reference to folder 1 end tell x -- folder 1 of application "Finder" === page 212a === tell application "Finder" set x to a reference to disk 99 of folder 1 of label "yoho" end tell get name of x -- error: Cant get name of disk 99 of folder 1 of label yoho === page 212b === set x to a reference to "hey" set y to a reference to 9 tell application "Finder" to set z to folder 1 class of x -- string class of y -- integer class of z -- folder === page 212c === tell application "Finder" to set x to folder 1 x as reference -- no error; its a reference === page 212d === tell application "Finder" to set x to folder 1 x -- folder "Mannie" of...; its a reference set x to a reference to y x -- y of script; its a reference === page 213a === on isRef(valueToTestAsRef) try valueToTestAsRef as reference return true on error return false end try end isRef -- and heres how to call it tell application "Finder" set x to folder 1 end tell isRef(x) -- true set x to "haha" isRef(x) -- false isRef(a reference to x)) -- true === page 213b === tell application "Finder" set x to folder 1 end tell name of x -- Mannie class of x -- folder set name of x to "Moe" === page 214a === tell application "Finder" set x to a reference to name of folder 1 end tell set x to "Moe" === page 214b === set x to 3 set y to a reference to x x = y -- false y = 3 -- false === page 214c === set x to 3 set y to a reference to x x = y -- false x + 0 = y + 0 -- true x is not less than y and x is not greater than y -- true === page 214d === tell application "Finder" set x to a reference to name of folder 1 end tell set contents of x to "Moe" === page 214e === set x to 10 set y to a reference to x set contents of y to 20 x -- 20 === page 215a === set x to 3 set y to a reference to x x = contents of y -- true === page 215b === set x to contents of "Mannie" contents of x -- "Mannie" === page 215c === set x to 3 set y to a reference to x contents of x = contents of y -- true === page 215d === set x to "Mannie" set contents of x to "Moe" -- error === page 215e === tell application "Finder" set x to folder 1 end tell x -- folder "Mannie" of desktop of application "Finder" set x to contents of x x -- folder "Mannie" of folder "Desktop" of folder "mattneub" of folder "Users" of startup disk of application "Finder" set x to contents of x x -- folder "Mannie" of folder "Desktop" of folder "mattneub" of folder "Users" of startup disk of application "Finder" === page 216a === tell application "BBEdit" set w to contents of word 4 of window 1 end tell w -- "test" === page 216b === tell application "BBEdit" set w to contents of (get word 4 of window 1) end tell w -- characters 11 thru 14 of text document 1 of application "BBEdit" === page 216c === tell application "BBEdit" set x to word 4 of window 1 set w to contents of x end tell w -- characters 11 thru 14 of text document 1 of application "BBEdit" === page 216d === tell application "BBEdit" set x to a reference to word 4 of window 1 set x to contents of x set w to contents of x end tell w -- characters 11 thru 14 of text document 1 of application "BBEdit" === page 217a === tell application "BBEdit" set x to a reference to word 4 of window 1 get contents of text of x -- "test" end tell === page 217b === local x set x to {1, 2, 3} set y to a reference to x get item 1 of y -- error: Cant make item 1 of x into type reference === page 217c === local y set x to {1, 2, 3} set y to a reference to x get item 1 of y -- 1 === page 217d === script myScript property x : 5 set y to a reference to x set contents of y to y + 1 display dialog x end script run myScript -- 6 === page 217e === script myScript property x : 5 display dialog x end script tell myScript set y to a reference to its x set contents of y to y + 1 run -- 6 end tell === page 218a === local x tell application "Finder" set x to folder 1 end tell on setName(theRef) set name of theRef to "Jack" end setName setName(x) === page 218b === on doubleRef(theRef) set contents of theRef to 2 * theRef end doubleRef script s property x : 5 display dialog x end script doubleRef(a reference to s's x) run s -- 10 === page 218c === on getNameOfAnything(theRef) return name of theRef end getNameOfAnything tell application "Finder" to set x to folder 1 tell application "Microsoft Entourage" to set y to message 1 of in box folder getNameOfAnything(x) -- "Mannie" getNameOfAnything(y) -- "Order Confirmation" === page 219a === script myScript property x : 3 return a reference to x end script set y to run myScript set contents of y to 10 myScript's x -- 10 === page 219b === on getFolderByNumber(n) local x tell application "Finder" set x to folder n end tell return x end getFolderByNumber getFolderByNumber(1) -- folder "Moe" of desktop of application "Finder" === page 219c === on findInList(what, L) repeat with i from 1 to count L if item i of L is what then return (a reference to item i of L) end if end repeat return end findInList local pep set pep to {"Mannie", "Moe", "Jack"} set contents of findInList("Moe", pep) to "Larry" pep -- {"Mannie", "Larry", "Jack"} === page 223a === date "5/25/2005" -- rewritten: date "Wednesday, May 25, 2005 12:00:00 AM" === page 223b === set s to "December 25, 800" date s -- date "Monday, December 25, 2800 12:00:00 AM" === page 223c === set s to "December 25, 1000" set d to date s set year of d to 800 d -- date "Monday, December 25, 0800 12:00:00 AM" === page 223d === set s to "8/10/2005 4:45 PM" (date s) + 56845 -- date "Thursday, August 11, 2005 8:32:25 AM" === page 223e === set s to "2/25" set d to date s -- date "Friday, February 25, 2005 12:00:00 AM" set d2 to date "10:30" of d -- date "Friday, February 25, 2005 10:30:00 AM" set d3 to date "1/24" of d2 -- date "Monday, January 24, 2005 10:30:00 AM" === page 223f === set s to "May 31" set d to date s set month of d to June d -- date "Friday, July 1, 2005 12:00:00 AM" === page 224a === set s to "8/10/2005 10:00 PM" set d to date s set hours of d to ((hours of d) + 100) d -- date "Monday, August 15, 2005 2:00:00 AM" === page 224b === set s to "May 31" set d to date s set d2 to d set month of d2 to June d -- date "Friday, July 1, 2005 12:00:00 AM" === page 225 === set s to "5/25/2005" set d1 to date s set t to "4PM" set d2 to date t set d3 to date (time string of d2) of d1 -- date "Wednesday, May 25, 2005 4:00:00 PM" === page 226a === tell application "Tex-Edit Plus" set text of window 1 to "Now is the winter" get word after character 3 of text of window 1 -- "is" end tell get word after character 3 of "Now is the winter" -- error: Cant get word after w === page 226b === set s to quoted form of "life's a \"bowl\" of cherries" do shell script "echo " & s -- "life's a \"bowl\" of cherries" === page 227a === words 1 thru 3 of "Now is the winter" -- {"Now", "is", "the"} text from word 1 to word 3 of "Now is the winter" -- "Now is the" === page 227b === set text item delimiters to ":" text items of "feathers:Users:mattneub" -- {"feathers", "Users", "mattneub"} set text item delimiters to "tt" text items of "Matt" -- {"Ma", ""} set text item delimiters to "s" set howMany to (count text items of "Mississippi") - 1 howMany -- 4, the number of ss in Mississippi === page 229a === set n to data utxt03910313030103BB03BA03B703C303C403B903C2 set n to n as Unicode text tell application "Finder" set name of folder "Mannie" to n end tell === page 229b === set L to {913, 787, 769, 955, 954, 951, 963, 964, 953, 962} set s to (path to desktop as string) & "tempFile" set f to a reference to file s open for access f with write permission repeat with aChar in L write aChar to f as small integer -- two bytes per character end repeat close access f === page 229c === set s to (path to desktop as string) & "tempFile" set f to a reference to file s open for access f set s to read f as Unicode text close access f === page 230 === set p to "print pack(\"U10\", 0x0391, 0x0313, 0x0301, 0x03BB, 0x03BA, " & "0x03B7, 0x03C3, 0x03C4, 0x03B9, 0x03C2);" set s to do shell script "perl -e " & quoted form of p === page 231 === tell application "Finder" activate set x to (the clipboard) end tell x as record === page 232a === set x to file "feathers:Users:mattneub:" -- error: Cant make file feathers:Users:mattneub: into type reference === page 232b === set x to a reference to file "feathers:Users:mattneub:" x -- file "feathers:Users:mattneub:" of script === page 233a === tell application "BBEdit" get file of window 1 -- alias "feathers:Users:mattneub:someFile" end tell === page 233b === tell application "GraphicConverter" set s to "feathers:Users:mattneub:Desktop:joconde" save window 1 in alias s as PICT -- error: File feathers:Users:mattneub:Desktop:joconde wasnt found end tell === page 233c === tell application "GraphicConverter" set s to "feathers:Users:mattneub:Desktop:joconde" save window 1 in file s as PICT -- error: GraphicConverter got an error: Cant get window 1. Access not allowed end tell === page 233d === tell application "GraphicConverter" set s to "feathers:Users:mattneub:Desktop:joconde" save window 1 in s as PICT end tell === page 233e === POSIX file "/Users/mattneub/" === page 234a === set x to POSIX file "/Users/mattneub" set y to file "feathers:Users:mattneub" === page 234b === set s1 to "/Users/mattneub" set x to POSIX file s1 set s2 to "feathers:Users:mattneub" set y to a reference to file s2 === page 234c === set s to "/alice/in/wonderland" POSIX file s -- file "feathers:alice:in:wonderland" === page 235a === tell application "BBEdit" set r to check syntax file "feathers:Users:mattneub:Desktop:testing.html" class of result_file of item 1 of r -- file specification end tell === page 235b === POSIX path of file "alice:in:wonderland" -- "/alice/in/wonderland", a misuse POSIX path of file "gromit" -- "/Volumes/gromit/" === page 235c === info for file "feathers:Users:mattneub:someFile" === page 235d === tell application "Finder" get owner of file "feathers:Users:mattneub:myFile" -- mattneub end tell === page 236a === set f to a reference to file "feathers:Users:mattneub:myFile" tell application "Finder" get owner of f -- error: Cant make class sown of file feathers:Users:mattneub:myFile into type reference end tell === page 236b === set empty to {} set pep to {"Mannie", "Moe"} set pep3 to "Jack" empty & pep & {pep3} -- {"Mannie", "Moe", "Jack"} === page 236c === tell application "Finder" set L to {name of folder 1, name of folder 2} set {oldname1, oldname2} to L set {name of folder 1, name of folder 2} to {"f1", "f2"} end tell === page 237a === set L1 to {"Mannie", "Moe"} set L2 to L1 set end of L1 to "Jack" item 3 of L2 -- "Jack" === page 237b === set L1 to {"Mannie", "Moe"} set L2 to {L1, "Pep"} set end of L1 to "Jack" item 3 of item 1 of L2 -- "Jack" === page 237c === set L to {"Mannie", "Moe"} set item 1 of L to "Larry" L -- {"Larry", "Moe"} === page 237d === set L to {"Moe"} set end of L to "Jack" set beginning of L to "Mannie" L -- {"Mannie", "Moe", "Jack"} === page 238a === on listInsert(L, what, ix) if ix = 1 then return {what} & L else return {item 1 of L} & listInsert(rest of L, what, ix - 1) end if end listInsert listInsert({"Mannie", "Jack"}, "Moe", 2) -- {"Mannie", "Moe", "Jack"} === page 238b === set L to {"Mannie", "Moe", "Jack"} set end of L to L count L -- 4 count item 4 of L -- 4 count item 4 of item 4 of item 4 of item 4 of item 4 of L -- 4 items 1 thru 3 of item 4 of item 4 of item 4 of L -- {"Mannie", "Moe", "Jack"} === page 238c === set L1 to {"Mannie", "Moe", "Jack"} set L2 to {"Curly", "Larry"} set end of L1 to L2 set end of L2 to L1 item 1 of item 4 of L1 -- "Curly" item 1 of item 3 of L2 -- "Mannie" === page 239 === item 2 of {23, "skiddoo", "catch", 22} whose class is integer -- error integer 2 of {23, "skiddoo", "catch", 22} -- 22 === page 240a === set R to {who:"Matt", town:"Ojai"} === page 240b === local who, town set {who:who, town:town} to {town:"Ojai", who:"Matt"} {who, town} -- {"Matt", "Ojai"} === page 240c === set R2 to {who:"Matt", town:"Ojai"} set R1 to R2 set who of R2 to "Jaime" R1 -- {who:"Jaime", town:"Ojai"} === page 240d === set L to {"Mannie", "Moe"} set R to {pep:L} set end of R's pep to "Jack" item 3 of L -- "Jack" === page 240e === set R to {who:"Matt", town:"Ojai"} set who of R to "Jaime" R -- {who:"Jaime", town:"Ojai"} set R to R & {friend:"Steve"} R -- {who:"Jaime", town:"Ojai", friend:"Steve"} === page 241a === set R to {who:"Matt", town:"Ojai"} & {who:"Jaime"} R -- {who:"Matt", town:"Ojai"} === page 241b === set R to {who:"Jaime", town:"Ojai"} set R to {friend:"Steve"} & R R -- {friend:"Steve", who:"Jaime", town:"Ojai"} === page 241c === set R to {who:"Jaime", town:"Ojai", friend:"Matt"} set R to {friend:"Steve"} & R R -- {friend:"Steve", who:"Jaime", town:"Ojai"} === page 241d === set R to {who:"Matt", town:"Ojai", cycle:null} set cycle of R to R who of cycle of cycle of cycle of cycle of R -- "Matt" === page 242a === set R to {|name|:"Matt", |character|:"impeccable", town:"Ojai", age:51} get |name| of R -- "Matt" get name of R -- error: Cant get name of... === page 242b === set town to "Ojai" set R to {name:"Matt", town:null} set town of R to town -- no problem === page 242c === set town to "Ojai" set R to {name:"Matt", town:null} tell R set town to town end tell R -- {name:"Matt", town:null} === page 242d === set town to "Ojai" set R to {name:"Matt", town:null} tell R set its town to town end tell R -- {name:"Matt", town:"Ojai"} === page 243 === global r set r to {name:"Matt", age:51} on getWhat(what) set s to "on run {r} get " & what & " of r end" run script s with parameters {r} end getWhat getWhat("name") === page 245a === on sendMeAString(s) if {class of s} is not in {string, Unicode text} then error "Can't make some data into the expected type." end if -- remaining code goes here, secure in the knowledge that s is a string . . . end sendMeAString === page 245b === tell application "Finder" set sidebar width of window 1 to "123" end tell === page 245c === tell application "Finder" set name of folder 1 to 6 -- error: Finder got an error: Cant make some data into the expected type end tell === page 246a === 9 as string -- "9" 9 as boolean -- error: Cant make 9 into type boolean === page 246b === set className to string 9 as className -- compile-time error: Expected class name but found identifier === page 247a === tell application "Finder" folder 1 as string end tell === page 247b === tell application "Finder" get "9" as integer end tell === page 247c === tell application "Finder" tell "9" get it as integer end tell end tell === page 247d === tell application "Finder" set x to folder 1 end tell name of x as integer === page 248a === tell application "Finder" get folder 1 as integer -- error: Finder got an error: Unknown object type end tell === page 248b === tell application "Finder" get name of folder 1 as integer -- error: Cant make Mannie into type integer end tell === page 248c === tell application "Finder" folder 1 as list -- error: Finder got an error: Unknown object type end tell === page 248d === tell application "Finder" {folder 1} end tell === page 249 === "1.1" as real -- 1.1 "1" as real -- 1.0 "1.0" as integer -- 1 "1.1" as integer -- error: Cant make 1.1 into type integer === page 250a === class of ("1" as number) -- integer class of ("1.1" as number) -- real === page 250b === "1.1" as number as integer -- 1 === page 250c === tell application "Finder" set v to (get version) end tell v as real -- error: Cant make 10.4.2 into type real === page 250d === string as string -- "string" italic as string -- "italic" === page 250e === display dialog string -- TEXT === page 251a === tell application "Finder" say (get name of disk 1) -- error: Finder got an error: feathers doesnt understand the say message end === page 251b === set a to alias "gromit:Users:matt2:reason:Resources:" POSIX path of a -- "/Volumes/gromit/Users/matt2/reason/Resources/" a as string -- "gromit:Users:matt2:reason:Resources:" a reference to file (a as string) -- file "gromit:Users:matt2:reason:Resources:" of script === page 251c === set s to "gromit:Users:matt2:reason:Resources:" s as alias -- alias "gromit:Users:matt2:reason:Resources:" === page 251d === set f to a reference to file "gromit:Users:matt2:reason:Resources:" f as alias -- alias "gromit:Users:matt2:reason:Resources:" POSIX path of f -- "/Volumes/gromit/Users/matt2/reason/Resources/" === page 252a === set s to "/Volumes/gromit/Users/matt2/reason/Resources/" POSIX file s as string -- "gromit:Users:matt2:reason:Resources:" s as POSIX file -- file "gromit:Users:matt2:reason:Resources:" === page 252b === on pathExists of s given posixStyle:b try if b then POSIX file s as alias else s as alias end if return true on error return false end try end pathExists pathExists of "gromit:Users:matt2" without posixStyle -- true pathExists of "/Volumes/gromit/Users/matt2" with posixStyle -- true === page 252c === set R to {name:"Matt", age:51} R as list -- {"Matt", 51} === page 253a === on listToRecord(L) script myScript return {class usrf:L} end script return run script myScript end listToRecord set R to listToRecord({"name", "haha", "age", 51}) R -- {|name|:"haha", age:51} === page 253b === {true} as string -- "true" === page 253c === {"Manny", {"Moe", "Jack"}} as string -- "MannyMoeJack" === page 254a === on containingFolder(s) set text item delimiters to ":" return (items 1 thru -2 of text items of s) as string end containingFolder containingFolder("feathers:Users:mattneub:Documents:someDoc") -- "feathers:Users:mattneub:Documents" === page 254b === on coerceForDisplay(L) try L as record on error s set c to characters of s set u to count c repeat with i from 1 to u if item i of c is "{" then exit repeat end repeat repeat with j from u to 1 by -1 if item j of c is "}" then exit repeat end repeat set text item delimiters to "" return (items i thru j of c) as string end try end coerceForDisplay display dialog coerceForDisplay({"pep", 3, {"Mannie", "Moe", "Jack"}}) -- {"pep", 3, {"Mannie", "Moe", "Jack"}} === page 255a === on feetToYards(ft) return ft as feet as yards as number end feetToYards feetToYards(3) -- 1.0 === page 255b === on convert(val, unit1, unit2) set text item delimiters to " " set conv to do shell script ({"units", unit1, unit2} as string) return val * (word 1 of paragraph 1 of conv as real) end convert convert(4, "feet", "meters") -- 1.2192 === page 256 === 1 and 1 -- compile-time error: Cant make 1 into type boolean === page 257a === 1 as boolean and 1 -- true === page 257b === "3" + "4" -- 7 === page 257c === 3 + 4 * 2 -- 11 3 * 4 + 2 -- 14 === page 257d === 2.32 * 100.0 div 1 -- 231 === page 260a === {1, 2} = {2, 1} -- false {name:"Matt", age:"51"} = {age:"51", name:"Matt"} -- true === page 260b === {"2"} = 2 -- false === page 260c === {"2"} 2 -- true === page 261 === {"2"} 2 and {"2"} 2 -- true === page 262a === {1, 2} contains 2 -- true === page 262b === {1, 2} contains {2} -- true === page 263a === {1, 2, 3} contains {2, 3} -- true === page 263b === {1, 2, 3} contains {1, 3} -- false {1, 2, 3} contains {3, 2} -- false === page 263c === {{1}, {2}} contains {2} -- false {{1}, {2}} contains {{2}} -- true === page 263d === {name:"Matt", age:"51"} contains {name:"Matt"} -- true {name:"Matt", age:"51"} contains {title:"Matt"} -- false {name:"Matt", age:"51"} contains {name:"Socrates"} -- false === page 263e === {name:"Matt", age:"51"} contains {age:"51", name:"Matt"} -- true === page 263f === {name:"Matt", age:"51"} contains {} -- true {} contains {name:"Matt", age:"51"} -- false === page 263g === "51" contains 5 -- true; string containment, "51" contains "5" 51 contains 5 -- false; list containment, {51} doesnt contain {5} === page 263h === {"7"} * 7 -- 49 === page 263i === {"7"} contains 7 -- false === page 264 === tell application "Microsoft Entourage" every contact contains contact 1 -- error: Cant make class cAbE id 1 of application "Microsoft Entourage" into type vector end tell === page 265a === "three" & 20 -- "three20" 3 & "twenty" -- {3, "twenty"} === page 265b === {"Mannie"} & "Moe" & "Jack" -- {"Mannie", "Moe", "Jack"} === page 265c === set text item delimiters to "" "butter" & {"field", 8} -- "butterfield8" === page 265d === {1, 2, 3} & {4, 5, 6} -- {1, 2, 3, 4, 5, 6} === page 265e === {1, 2, 3} & {{4, 5, 6}} === page 265f === set L1 to {} set L2 to {"mannie"} set L1 to L1 & L2 set item 1 of L1 to "moe" L2 -- {"moe"} === page 266a === copy L1 & L2 to L1 === page 266b === set s to "anti" set s to s & "dis" set s to s & "establishment" set s to s & "arianism" === page 266c === set text item delimiters to "" set L to {} set end of L to "anti" set end of L to "dis" set end of L to "establishment" set end of L to "arianism" set s to L as string === page 266d === set r to {who:"Jaime", town:"Ojai"} & {who:"Matt", friend:"Steve"} r -- {who:"Jaime", town:"Ojai", friend:"Steve"} === page 266e === set R1 to {} set R2 to {name:"Matt"} set R1 to R1 & R2 set name of R1 to "Neuburg" R2 -- {name:"Neuburg"} === page 267a === 3 + 4 * 2 -- 11 (3 + 4) * 2 -- 14 === page 267b === set r to random number round r rounding up === page 267c === round random number rounding up -- compile-time error: A application constant [sic] or consideration cant go after this identifier === page 267d === round (random number) rounding up === page 267e === tell application "System Events" copy name of every process where it is frontmost to theProc end tell === page 268a === tell application "System Events" copy get name of every process where it is frontmost to theProc -- compile-time error: Expected into, to, etc. but found get end tell === page 268b === tell application "System Events" copy (get name of every process where it is frontmost) to theProc end tell === page 268c === tell application "System Events" set L to name of every process frontmost of process item 1 of L -- error: No result was returned from some part of this expression end tell === page 268d === tell application "System Events" set L to name of every process frontmost of process (item 1 of L) end tell === page 269a === tell application "Finder" set f1 to folder 1 set f2 to folder "Mannie" f1 = f2 -- false end tell === page 269b === tell application "Finder" name of every folder whose name contains "E" end tell === page 270a === tell application "Finder" considering case name of every folder whose name contains "E" end considering end tell -- {"emptyFolder", "Test Me"} === page 270b === tell application "Finder" set L to name of every folder end tell set L2 to {} considering case repeat with aName in L if aName contains "E" then set end of L2 to contents of aName end if end repeat end considering === page 271 === property pi : 3 AppleScript's pi -- 3.14159265359 === page 273 === set text item delimiters to ":" text item 1 of (path to system folder as string) === page 274 === display dialog AppleScript's version AppleScript's version as real === page 282 === set x to random number from 1 to 10 set guess to text returned of (display dialog "Pick a number from 1 to 10" default answer "") try set guess to guess as number on error return end try if guess < 1 or guess > 10 then display dialog "I said from 1 to 10!" else if guess < x then display dialog "Too small. I was thinking of " & x else if guess > x then display dialog "Too big. I was thinking of " & x else display dialog "Just right." end if === page 283 === repeat display dialog "Prepare to loop forever." exit repeat end repeat display dialog "Just kidding." === page 284a === repeat 3 times display dialog "This is really boring." end repeat display dialog "ZZzzzz...." === page 284b === set L to {2, -5, 33, 4, -7, 8} set total to 0 repeat (count L) times repeat 1 times set x to item 1 of L set L to rest of L if x < 0 then exit repeat set total to total + x end repeat end repeat total -- 47 === page 284c === set response to "Who's there?" repeat while response = "Who's there?" set response to button returned of (display dialog "Knock knock!" buttons {"Enough!", "Who's there?"}) end repeat === page 285 === set response to "" repeat until response = "Enough!" set response to button returned of (display dialog "Knock knock!" buttons {"Enough!", "Who's there?"}) end repeat === page 286 === repeat with x from 3 to 1 by -1 display dialog x end repeat display dialog "Blast off!" === page 287a === repeat with x in {1, 2, 3} display dialog x -- 1, 2, 3 end repeat === page 287b === repeat with x in {1, 2, 3} if x = 2 then display dialog "2" end if end repeat === page 287c === repeat with x in {1, 2, 3} if contents of x = 2 then display dialog "2" end if end repeat === page 287d === set L1 to {1, 2, 3} set L2 to {} repeat with x in L1 set end of L2 to x end repeat L2 -- {item 1 of {1, 2, 3}, item 2 of {1, 2, 3}, item 3 of {1, 2, 3}} === page 287e === set L1 to {1, 2, 3} set L2 to {} repeat with x in L1 set end of L2 to contents of x end repeat L2 -- {1, 2, 3} === page 288a === set L to {1, 2, 3} repeat with x in L set contents of x to item x of {"Mannie", "Moe", "Jack"} end repeat L -- {"Mannie", "Moe", "Jack"} === page 288b === on findInList(what, L) repeat with anItem in L if contents of anItem is what then return anItem end if end repeat return end findInList local pep set pep to {"Mannie", "Moe", "Jack"} set contents of findInList("Moe", pep) to "Larry" pep -- {"Mannie", "Larry", "Jack"} === page 288c === set L to {1, 2, 3} repeat with x in L set L to {"Mannie", "Moe", "Jack"} display dialog x -- 1, then 2, then 3 end repeat === page 288d === set L to {1, 2, 3} repeat with x in L display dialog x -- 1 (every time) set beginning of L to contents of x end repeat L -- {1, 1, 1, 1, 2, 3} === page 289 === set total to 0 tell application "Finder" count folders -- 6 repeat with x in every folder set total to total + 1 end repeat end tell total -- 50 === page 290 === tell application "BBEdit" repeat with w in (every word of document 1 where its text begins with "t") set text of w to "howdy" end repeat end tell === page 291 === tell application "BBEdit" set L to (get every word of document 1 where its text begins with "t") repeat with w in (reverse of L) set text of w to "howdy" end repeat end tell === page 292a === get frontmost of application "Finder" -- false === page 292b === using terms from application "Finder" set f to a reference to folder 1 end using terms from === page 293a === tell application "Finder" using terms from application "Microsoft Entourage" get name of folder 1 -- error: Finder got an error: Cant get name of folder 1 end using terms from end tell === page 293b === using terms from application "Finder" tell application someVariable get name of folder 1 end tell end using terms from === page 293c === tell application someVariable using terms from application "Finder" get name of folder 1 end using terms from end tell === page 294a === set whatMachine to text returned of (display dialog "Machine to connect to:" default answer "eppc://") -- I enter eppc://duck.local and hit OK; the password dialog appears and I fill it out correctly tell application "Finder" of machine whatMachine using terms from application "Finder" get name of disk 1 -- "OmniumGatherum" end using terms from end tell === page 294b === using terms from application "Microsoft Entourage" set n1 to a reference to name of folder 1 of application "Microsoft Entourage" end using terms from using terms from application "Finder" set n2 to a reference to name of folder 1 of application "Finder" end using terms from on getThing(R) return (get contents of R) end getThing getThing(n1) -- "Inbox" getThing(n2) -- "Mannie" === page 295 === using terms from application "someAppThatMightBeMissing" set s to "someAppThatMightBeMissing" tell application s doYourThing end tell end using terms from === page 296 === with timeout of 100000 seconds tell application "Finder" get every application file of entire contents of disk 1 where its creator type is "aplt" end tell end timeout === page 297 === tell application "FileMaker Pro" with transaction tell database 1 show every record set f to create new request set cell "lastname" of f to "neuburg" find end tell end transaction end tell === page 300a === ignoring hyphens, expansion and punctuation considering white space but ignoring case and diacriticals "a-" = "!" -- true end considering end ignoring === page 300b === set bigEpsilon to data utxt0395 as Unicode text set littleEpsilon to data utxt03B5 as Unicode text ignoring case bigEpsilon = littleEpsilon -- true end ignoring === page 300c === "1.10" > "1.9.3" -- false considering numeric strings "1.10" > "1.9.3" -- true end considering === page 301 === error "Things fall apart, the centre cannot hold." === page 303a === set x to "Cancel" try set x to button returned of (display dialog "Press a button.") end try display dialog "You pressed " & x === page 303b === set L to {} set x to 1 tell application "Finder" try repeat set end of L to name of disk x set x to x + 1 end repeat end try end tell L -- {"feathers", "gromit", "Network"} === page 304a === on num(what) try return what as number on error s number i partial result p from f to t set s to "Handler num got an error: " & s error s number i partial result p from f to t end try end num num("howdy") -- error: Handler num got an error: Can't make "howdy" into type number === page 304b === on askUser() try set x to text returned of (display dialog "Give me a number:" default answer "") set x to (x as number) on error askUser() end try error x end askUser try askUser() on error what display dialog "Your number is " & what end try === page 305 === on getFavoriteColor() try set r to display dialog "What is your favorite color?" default answer "" on error error number 1001 end try set s to text returned of r if s = "" then error number 1000 return s end getFavoriteColor set c to "" repeat until c is not "" try set c to getFavoriteColor() on error number n if n = 1000 then display dialog "You didn't enter a color!" buttons "OK" else if n = 1001 then display dialog "Why did you cancel? Tell me!" buttons "OK" end if end try end repeat display dialog "Aha, you like " & c & ", eh?" === page 306a === set n to text returned of (display dialog "What disk would you like the name of?" default answer "") try tell application "Finder" to set x to name of disk (n as integer) display dialog x on error e number n partial result p from f to t if n = -1728 then display dialog "I don't think that disk exists. " & e else error e number n partial result p from f to t end if end try === page 306b === on error e number -1728 display dialog "I don't think that disk exists. " & e end try === page 306c === set n to text returned of (display dialog "What disk would you like the name of?" default answer "") try try tell application "Finder" to set x to name of disk (n as integer) display dialog x on error e number -1728 display dialog "I don't think that disk exists. " & e end try on error e number -1700 display dialog "I don't think that was an integer." end try === page 307a === on askUser() set n to text returned of (display dialog "What disk would you like the name of?" default answer "") try tell application "Finder" to set x to name of disk (n as integer) display dialog x on error e number -1728 display dialog "I don't think that disk exists. " & e end try end askUser try askUser() on error e number -1700 display dialog "I don't think that was an integer." end try === page 307b === try tell application "Finder" activate with timeout of 1 second display dialog "Press a button." giving up after 2 end timeout end tell on error number -1712 activate display dialog "Ha ha, not fast enough!" end try === page 308 === set d to "window 1" set p to "What Finder object would you like the name of?" set r to display dialog p default answer d set s to text returned of r set s to "tell app \"Finder\" to get name of " & s try set res to run script s display dialog res on error display dialog "Sorry, that didn't work." end try === page 314a === tell application "iTunes" tell application "Finder" count folders end tell end tell === page 314b === tell application "Finder" using terms from application "iTunes" count folders -- error: The variable folders is not defined end using terms from end tell === page 315 === local count -- compile-time error: Expected variable name or property but found command name === page 316a === set sel to {length:2, offset:4} -- compile-time error: Expected variable name, class name or property but found command name === page 316b === local desktop -- compile-time error: -- Expected variable name or property but found application constant or consideration === page 316c === set desktop to 7 -- compile-time error: Cant set desktop to 7. Access not allowed === page 316d === tell application "Finder" set container to 7 -- compile-time error: Cant set class ctnr to 7. Access not allowed end tell === page 316e === tell application "Finder" script eject -- compile-time error: Expected tell, etc. but found script end script end tell === page 317a === set count to 0 -- error: Cant set count of 0 to === page 317b === set year to 2005 -- error: Cant make year into type reference === page 317c === local year set year to 2005 -- fine === page 317d === local container, x set container to "howdy" tell application "Finder" set x to container end tell x -- container, not howdy === page 317e === set home to "Ojai" tell application "Finder" get home -- folder "mattneub" of folder "Users" of startup disk of application "Finder" end tell === page 317f === on beep (what) display dialog what end beep beep 3 -- 3, not beep beep beep === page 318a === set count to 0 set myVar to 10 === page 318b === local year set year to 2005 -- fine === page 319a === local bounds tell application "Finder" set bounds to (get bounds of item 1) end tell bounds -- {-33, -33, 31, 31} === page 319b === tell application "Finder" set bounds to (get bounds of item 1) -- error: Finder got an error: Cant set bounds to {-33, -33, 31, 31} end tell === page 319c === local home tell application "Finder" set home to (get bounds of item 1) -- error: Finder got an error: Cant set home to {-33, -33, 31, 31} end tell === page 320a === local |count| set |count| to 0 set |year| to 2005 set sel to {length:2, |offset|:4} local |desktop| tell application "Finder" set |container| to 7 end tell tell application "Finder" script |eject| end script end tell on |beep|(what) display dialog what end |beep| beep 1 -- beeps |beep|("howdy") -- howdy === page 320b === set home to "Ojai" tell application "Finder" get home -- folder "mattneub" of folder "Users" of startup disk of application "Finder" end tell === page 321a === set home to "Ojai" tell application "Finder" get my home -- error: Cant make home directory into type reference end tell === page 321b === set home to "Ojai" tell application "Finder" get |home| -- "Ojai" end tell === page 321c === on reverseString(s) set text item delimiters to "" return (reverse of characters of s) as string end reverseString tell application "Finder" set name of folder 1 to reverseString(get name of folder 1) -- error: Finder got an error: Cant continue reverseString end tell === page 322a === local folder set folder to 5 tell application "Finder" set |folder| to 10 end tell folder -- 5, not 10 === page 322b === local |folder| set |folder| to 5 tell application "Finder" set |folder| to 10 end tell |folder| -- 10 === page 323a === tell application "BBEdit" tell text window 1 offset of "i" in (get contents of word 1) -- compile-time error: access not allowed end tell end tell === page 323b === tell application "Finder" get name of eject -- compile-time error: Expected expression but found command name end tell === page 323c === tell application "Finder" set container to "howdy" -- compile-time error: Cant set class ctnr to howdy. Access not allowed end tell === page 323d === tell application "Finder" duplicate x by y -- compile-time error: Expected end of line but found by end tell === page 323e === tell application "Finder" get name 1 -- compile-time error: Expected end of line but found number end tell === page 323f === tell application "Finder" folder -- folder (the class name) folders -- {...}, a list of references to every folder folders 1 -- compiles as folder 1 folder 1 thru 2 -- compiles as folders 1 thru 2 end tell === page 324a === tell application "Finder" to get column 1 of desktop === page 324b === tell application "Finder" to eject the item of file 1 === page 324c === tell application "Finder" tell folder 1 make new extension hidden end tell end tell === page 324d === tell application "Finder" to folder the item === page 325a === get name of class cdis 1 of application "Finder" -- "feathers" === page 325b === path to application support from user domain -- alias "feathers:Users:mattneub:Library:Application Support:" tell application "System Events" path to application support from user domain -- alias "feathers:Library:Application Support:" end tell === page 326a === tell application "System Events" path to application support from constant fldmfldu -- alias "feathers:Users:mattneub:Library:Application Support:" end tell === page 326b === set userdomain to user domain tell application "System Events" path to application support from userdomain -- alias "feathers:Users:mattneub:Library:Application Support:" end tell === page 326c === property userdomain : run script ("constant fldmfldu") tell application "System Events" path to application support from userdomain -- alias "feathers:Users:mattneub:Library:Application Support:" end tell === page 327a === tell application "iTunes" display dialog (kind of source 1 as string) -- library end tell === page 327b === set R to {class kACD:"audio CD", class kLib:"library", class kTrk:"track listing"} tell application "iTunes" set k to (get kind of source 1) display dialog (get property k in R) -- library end tell === page 328a === local clipboard, tester set clipboard to "Mannie" -- sets the variable clipboard set the tester to "Moe" -- sets the variable tester (ignoring the) set the clipboard to "Jack" -- sets the system scrap === page 328b === tell application "Finder" get text item delimiters -- error: Finder got an error: Cant get text item delimiters end tell === page 328c === tell application "Finder" get my text item delimiters -- fine end tell === page 329 === tell application "Finder" get space end tell === page 336 === tell application "Finder" class of item 1 of desktop -- document file (not item) end tell === page 338 === tell application "BBEdit" set d to document 1 -- result is a reference get name of d -- sends Apple event to BBEdit end tell === page 339a === tell application "BBEdit" set d to find tag "style" start_offset 0 class of d -- tag result start_offset of tag of d -- 225; no Apple event is sent end_offset of tag of d -- 259; no Apple event is sent end tell === page 339b === tell application "BBEdit" set d to find tag "style" start_offset 0 end tell start_offset of tag of d -- error: Cant get tag of... === page 345a === tell application "iTunes" get playlist "library" -- library playlist id 40 of source id 35 end tell === page 345b === tell application "Finder" get folder 1 -- folder "Mannie" of desktop end tell === page 345c === tell application "Microsoft Entourage" get email address 1 of contact 1 -- "matt@tidbits.com" get label of email address 1 of contact 1 -- home end tell === page 346a === tell application "Eudora" to count messages of mailbox "In" === page 346b === tell application "Finder" to get item 1 of Finder window 1 === page 346c === tell application "Finder" to get files 1 thru 2 of folder 1 === page 347a === tell application "Eudora" to get mailbox 1 -- error: Cant get mailbox 1 === page 347b === tell application "Eudora" to get name of mailbox 1 -- "In" === page 347c === tell application "Eudora" to count messages of mailbox 1 === page 347d === tell application "Eudora" to count mailboxes -- error: Cant get every mailbox === page 347e === tell application "Microsoft Entourage" tell folder 1 tell message 1 tell recipient 1 get address of address -- error: Cant get address of address end tell end tell end tell end tell === page 348a === tell application "Microsoft Entourage" tell folder 1 tell message 1 tell recipient 1 get address of its address -- "matt@tidbits.com" end tell end tell end tell end tell === page 348b === tell application "Finder" to get class of desktop -- desktop === page 348c === tell application "Microsoft Entourage" get path to desktop as string end tell === page 349 === tell application "GraphicConverter" set s to "feathers:Users:mattneub:Desktop:joconde" save window 1 in s as PICT end tell === page 350a === tell application "Finder" repeat with d in (get every disk) -- do something here end repeat end tell === page 350b === tell application "Finder" to make Finder window === page 351 === tell application "Eudora" make new message at end of mailbox "Out" end tell === page 352a === tell application "NoteTaker" tell current notebook tell current page make new entry at beginning of entries end tell end tell end tell === page 352b === tell application "BBEdit" tell window 1 make new word at word 2 with data "howdy" end tell end tell === page 352c === tell application "TextEdit" tell text of document 1 make new word at word 2 with data "howdy" end tell end tell === page 352d === tell application "Finder" make new folder at folder 1 end tell === page 353a === tell application "Mailsmith" tell message window 1 make new to_recipient with properties {address:"matt@tidbits.com"} end tell end tell === page 353b === tell application "Address Book" name of selection -- error: Address Book got an error: Cant make name of selection into type reference end tell === page 354 === tell application "Address Book" set L to {} repeat with aThing in (get selection) set end of L to (get name of aThing) end repeat L end tell === page 355a === tell application "Eudora" delete message 1 of mailbox "Out" -- error: Message 1 of mailbox Out doesnt understand the delete message end tell === page 355b === tell application "Eudora" move message 1 of mailbox "Out" to end of mailbox "Trash" end tell === page 356 === tell application "Finder" get every disk as alias list -- {alias "feathers:", alias "gromit:", alias "Network:"} end tell === page 361a === set f to "gromit:Applications (Mac OS 9):SimpleText" tell application f to display dialog "hello" -- clearly the Classic display dialog === page 361b === set f to "gromit:Applications (Mac OS 9):SimpleText" tell application f to get min monitor depth -- compile-time error: Expected end of line, etc. but found identifier === page 362 === set f to "gromit:Applications (Mac OS 9):SimpleText" tell application f to event aevtgmnd -- 8 === page 363a === try tell me to event ascrgdut end try === page 363b === try run script "get the ticks" on error -- evidently it isn't installed set jons to choose file with prompt "Please find Jon's Commands:" set sa to path to scripting additions from user domain tell application "Finder" to duplicate jons to sa try tell me to event ascrgdut end try end try display dialog (run script "get the ticks") -- 1974834 === page 364 === set r to display dialog "Quick! Pick a Pep Boy!" buttons {"Mannie", "Moe", "Jack"} with icon caution giving up after 3 set favoritePepBoy to button returned of r if favoritePepBoy is "" and gave up of r then set notFastEnough to true set whoIsIt to text returned of (display dialog "What is your name?" default answer "" buttons {"OK"} default button "OK") === page 365a === tell application "Finder" display alert "Pep Alert" message "Mannie, Moe, and Jack welcome you." end tell === page 365b === set p to choose from list {"Mannie", "Moe", "Jack"} with prompt "Pick a Pep Boy:" === page 365c === set f to choose file of type {"public.text"} without invisibles === page 365d === set f to choose folder with prompt "Pick a folder:" === page 365e === set f to choose file name with prompt "Where shall I save this stuff?" === page 366a === set theApp to choose application as alias tell application "Finder" set isScriptable to has scripting terminology of theApp end tell if isScriptable then display dialog "It's scriptable!" === page 366b === choose URL showing File servers -- "afp://duck.local." === page 366c === choose remote application -- application "Finder" of machine "eppc://192.168.0.4/?uid=501&pid=178" using terms from application "Finder" set ap to choose remote application -- I choose Finder on remote machine -- username/password dialog appears, I fill it out tell ap get name of window 1 -- Desktop end tell end using terms from === page 367a === choose color default color {9000, 10000, 50000} -- {50000, 9000, 10000} === page 367b === beep === page 367c === alert volume of (get volume settings) -- 75 === page 367d === set volume output volume 100 alert volume 100 beep === page 368a === tell application "SpeechRecognitionServer" set s to listen for {"yes", "no"} with prompt "Would you like me to beep?" giving up after 10 end tell if s is "yes" then say "Okay, I will beep now." displaying "Okay." beep else say "Okay, then I won't." displaying "Okay." end if === page 368b === set v to system version of (system info) display dialog "You are running system " & v & "!" === page 368c === set n to system attribute "sysv" set s to "print sprintf \"%lx\", " & n set v to do shell script "perl -e " & quoted form of s set L to characters of v set v to "." & item -1 of L set v to "." & item -2 of L & v set v to ((items 1 thru -3 of L) as string) & v display dialog "You are running system " & v & "!" === page 368d === system attribute "SHELL" -- "/bin/bash" === page 369a === path to desktop -- alias "feathers:Users:mattneub:Desktop:" path to "cmnu" -- alias "feathers:Library:Contextual Menu Items:" === page 369b === path to application "Finder" -- alias "feathers:System:Library:CoreServices:Finder.app:" === page 369c === display dialog ((path to resource "description.rtfd") as string) -- feathers:Users:mattneub:Library:Scripts:myScriptBundle.scptd:Contents: Resources:description.rtfd set f to path to resource "app.icns" in bundle alias "feathers:Applications:Mail.app:" display dialog "Time to check your mail!" with icon f === page 369d === list disks -- {"feathers", "gromit", "Network"} === page 370a === list folder (path to home folder) -- {".bash_history", ".CFUserTextEncoding", ".DS_Store", ".ssh", ...} === page 370b === set uf to (path to home folder as string) set L to list folder uf set s to {} repeat with f in L -- collect sizes of all items set end of s to size of (info for file (uf & f)) end repeat set maxItem to 0 set maxVal to 0 repeat with i from 1 to (count s) -- find biggest size if item i of s > maxVal then set maxItem to i set maxVal to item i of s end if end repeat display dialog "The biggest thing in your home folder is: " & item maxItem of L === page 371a === set f to (path to desktop as string) & "newfile.txt" set ff to open for access file f close access ff === page 371b === set f to (path to desktop as string) & "someUTF16file.txt" set ff to open for access file f set d1 to read ff as Unicode text d1 -- "MannieMoeJack" -- testing delimiter parameter set notsign to "" as Unicode text set L to read ff from 1 as Unicode text using delimiter notsign L -- {"Mannie", "Moe", "Jack"} -- testing before parameter set d2 to read ff from 1 as Unicode text before notsign close access ff d2 -- "Mannie" === page 371c === set f to a reference to file ((path to desktop as string) & "justTesting") open for access f with write permission write {"Mannie", "Moe", "Jack"} as list to f close access f open for access f set L to read f as list close access f L -- {"Mannie", "Moe", "Jack"} === page 372a === write "Howdy" to f set ourEof to get eof of f write "Doody" to f starting at ourEof + 1 === page 372b === set f to open for access ((path to desktop as string) & "testing") close access f === page 372c === set f to ((path to desktop as string) & "testing") open for access f close access alias f === page 372d === set f to ((path to desktop as string) & "testing") open for access f close access f -- error: Cant make feathers:Users:mattneub:Desktop:testing into type file === page 373a === set pep to {"Mannie", "Moe", "Jack"} set f to (path to current user folder as string) & "testFile" try set fNum to open for access file f with write permission on error close access file f return end try try set eof fNum to 0 -- erase if exists set eof fNum to (count pep) * 32 repeat with i from 1 to (count pep) write item i of pep to fNum starting at (i - 1) * 32 end repeat close access fNum on error close access fNum end try === page 373b === set f to choose file of type "TEXT" try set fNum to open for access f on error close access f return end try set L to {} try set ct to (get eof fNum) / 32 repeat with i from 1 to ct set end of L to read fNum from (i - 1) * 32 before ASCII character 0 -- read up to but not including null end repeat close access fNum on error close access fNum end try L -- {"Mannie", "Moe", "Jack"} === page 375a === -- user has copied a files icon in the Finder set r to the clipboard as record -- {string:"Hawaii Itinerary.pdf", class ut16:"Hawaii Itinerary.pdf", class hfs :data hfs 0000...0000, class utf8:"Hawaii Itinerary.pdf", Unicode text:"Hawaii Itinerary.pdf", picture:data PICT0A38...000FF, class icns:data icns6963...0000, class furl:file "feathers:Users:mattneub:Desktop:Hawaii Itinerary.pdf"} type identifier of (info for class furl of r) -- "com.adobe.pdf" the clipboard as class furl -- works too === page 375b === set L to {} repeat 10 times if (random number 1) as boolean then set end of L to "heads" else set end of L to "tails" end if end repeat L -- {"heads", "tails", "heads", "heads", "heads", "tails", "heads", "heads", "heads", "heads"} === page 376 === -- this first one lets user choose, presents the Select volumes to mount dialog set s to choose URL showing File servers mount volume s as user name "mattneub" with password "teehee" -- these next ones present no dialogs mount volume "afp://matt%20neuburg:teehee@duck.local/OmniumGatherum" mount volume "afp://duck.local/OmniumGatherum" as user name "matt neuburg" with password "teehee" -- this one presents username/password dialog and volume dialog mount volume "afp://duck.local" === page 380a === set x to 1 tell application "Finder" set f1 to folder "f1" set f2 to folder "f2" repeat while ((count items of f1) < (count items of f2)) make new folder at f1 with properties {name:("f" & x)} set x to x + 1 end repeat end tell === page 380b === set x to 1 tell application "Finder" set f1 to folder "f1" set f2 to folder "f2" set c1 to count items of f1 set c2 to count items of f2 repeat while c1 < c2 make new folder at f1 with properties {name:("f" & x)} set x to x + 1 set c1 to c1 + 1 end repeat end tell === page 380c === tell application "BBEdit" repeat with w in every word of document 1 if contents of text of w begins with "t" then change case w making raise case end if end repeat end tell === page 381a === tell application "BBEdit" set L to (get every word of document 1) repeat with w in L if contents of text of w begins with "t" then change case w making raise case end if end repeat end tell === page 381b === tell application "BBEdit" set L to (get every word of document 1 where contents of text of it begins with "t") repeat with w in L change case w making raise case end repeat end tell === page 381c === tell application "Finder" set L to (get every folder) set L2 to {} repeat with f in L set end of L2 to name of f end repeat end tell === page 381d === tell application "Finder" set L to (get name of every folder) end tell === page 382a === set L to {} set total to 0 set bignum to 5000 repeat with i from 1 to bignum set end of L to i end repeat repeat with i from 1 to bignum set total to total + (item i of L) end repeat total -- 12502500, and it takes about 22 seconds to run on my machine === page 382b === set L to {} set refL to a reference to L set total to 0 set bignum to 5000 repeat with i from 1 to bignum set end of L to i end repeat repeat with i from 1 to bignum set total to total + (item i of refL) end repeat total -- 12502500, and it took less than a second === page 382c === set L to {} set total to 0 set bignum to 5000 repeat with i from 1 to bignum set end of L to i end repeat repeat with i from 1 to bignum set total to total + (item i of my L) end repeat total -- 12502500, and it took less than a second === page 383 === on myHandler() set L to {} script myScript property refL : L end script set total to 0 set bignum to 5000 repeat with i from 1 to bignum set end of L to i end repeat repeat with i from 1 to bignum set total to total + (item i of myScript's refL) end repeat return total end myHandler myHandler() -- 12502500, and it took less than a second === page 384a === set t to the ticks repeat 5000 times tell application "Finder" to get offset of "i" in "ticks" end repeat set t1 to (the ticks) - t set t to the ticks repeat 5000 times tell me to get offset of "i" in "ticks" end repeat set t2 to (the ticks) - t return {t1, t2} -- {944, 71} === page 384b === set x to (get current date) repeat 500 times tell application "iTunes" get name of it end tell end repeat set y to (get current date) set z to (y - x) tell application "Finder" activate display dialog z end tell === page 389a === tell application "Finder" of machine "eppc://duck.local" -- puts up the username/password dialog get name of every window end tell tell application "Finder" of machine "eppc://mattneub:teehee@duck.local" -- avoids the username/password dialog get name of every window end tell set s to "eppc://mattneub:teehee@duck.local/Finder" -- incorporates machine specifier into application specifier tell application s get name of window 1 end tell set s to "eppc://mattneub:teehee@192.168.0.4/Finder" -- uses IP number instead of Bonjour name tell application s get name of window 1 end tell set s to "eppc://mattneub:teehee@duck.local/?uid=501&pid=179" -- uses pid instead of application name tell application s get name of window 1 end tell === page 389b === set s to "eppc://mattneub:teehee@duck.local/Finder?uid=501" using terms from application "Finder" tell application s get name of every disk -- {"OmniumGatherum", "Network", "SecretSharer", "Puma"} end tell end using terms from === page 390a === tell application "Finder" of machine "eppc://duck.local" say "Watson, come here, I want you." end tell === page 390b === tell application "Finder" of machine "eppc://duck.local" display dialog "Watson, come here, I want you." -- error: Finder got an error: No user interaction allowed end tell === page 390c === set s to "eppc://mattneub:teehee@duck.local/Finder?uid=501" using terms from application "Finder" tell application s get name of every process -- {"loginwindow", "Dock", "SystemUIServer", "Finder", "LaunchBar", "UniversalAccess", "System Events"} end tell end using terms from === page 391a === tell application "Finder" of machine "eppc://duck.local" open item "OmniumGatherum:Applications:Utilities:Terminal.app" end tell === page 391b === set m to "eppc://mattneub:teehee@duck.local" tell application "Finder" of machine m using terms from application "Finder" open application file id "com.barebones.BBEdit" end using terms from end tell tell application "BBEdit" of machine m using terms from application "BBEdit" set contents of document 1 to "Hello, world!" end using terms from end tell === page 391c === set L to {} repeat with i from 501 to 520 set m to "eppc://mattneub:teehee@duck.local/?uid=" & (i as string) using terms from application "Finder" try tell application "Finder" of machine m get (desktop as string) set end of L to i end tell end try end using terms from end repeat L -- {501, 502} === page 392a === on test(m) tell application "Finder" of machine m set n to (get name of window 1) end tell display dialog n end test test("eppc://mattneub:teehee@duck.local/?uid=501") -- mattneub test("eppc://mattneub:teehee@duck.local/?uid=502") -- guest === page 392b === tell application "Finder" to get name of window 1 -- mattneub set m to "eppc://mattneub:teehee@localhost/?uid=502" tell application "Finder" of machine m get name of window 1 -- mrclean end tell === page 394a === tell application "http://superhonker.userland.com/rpc2" call xmlrpc {method name:"examples.getStateName", parameters:30} -- "New Jersey" end tell === page 394b === tell application "http://superhonker.userland.com" call soap {method name:"getStateName", SOAPAction:"/examples", parameters:{statenum:30}} -- "New Jersey" end tell === page 394c === on generalSOAP(u, m, s, a, p) using terms from application "http://www.apple.com/placebo" tell application u return call soap {method name:m, method namespace uri:s, parameters:p, SOAPAction:a} end tell end using terms from end generalSOAP generalSOAP("http://services.xmethods.net:80/soap", "getQuote", "urn:xmethods-delayed-quotes", "", {Symbol:"AAPL"}) -- 74.93 === page 396a === tell application "System Events" get full name of current user make new login item at end of login items with properties {path:"/Applications/Safari.app"} end tell === page 396b === tell application "System Events" name of folder 1 of desktop folder of user domain -- "Mannie" end tell === page 396c === tell application "Finder" to set f to (get file 1 as string) tell application "System Events" try set f to audio file f on error error "Not an audio file." end try set k to kind of f tell (get contents of f) set t to (its duration) / (its time scale) set min to t div 60 set sec to round (t mod 60) rounding as taught in school end tell return k & ", " & min & ":" & sec -- MP3 Audio File, 2:43 end tell === page 397a === tell application "System Profiler" set s to (XML text of document 1) end tell on findElementWithValue(e, v) tell application "System Events" repeat with i from 1 to (count XML elements of e) if value of XML element i of e is v then return i end if end repeat end tell error "not found" end findElementWithValue tell application "System Events" set x to make new XML data with data s set e to XML element 1 of XML element 1 of x set e to first XML element of e where value of XML element 2 of it is "SPHardwareDataType" set i to my findElementWithValue(e, "_items") set e to XML element 1 of XML element (i + 1) of e set i to my findElementWithValue(e, "machine_name") return value of XML element (i + 1) of e -- iMacG5 end tell === page 397b === tell application "System Profiler" set s to (XML text of document 1) end tell tell application "System Events" set p to make new property list item with data s set p to property list item 1 of p set p to property list item "_items" of p set p to property list item 1 of p return value of property list item "machine_name" of p -- iMacG5 end tell === page 398 === set f to (path to application "Keychain Scripting") tell application "Keychain Scripting" to quit tell application "Finder" to open f delay 5 -- that ought to do it! tell application "Keychain Scripting" tell (get current keychain) set k to (get first generic key whose name is "mattneub") get {account, description, service, password} of k -- {"mattneub", "application password", "iTools", "teehee"} end tell end tell === page 399a === tell application "Image Events" set f to (path to desktop as string) & "bigImage.tiff" set f2 to POSIX path of (path to desktop) & "/smallerImage.tiff" set im to open file f scale im by factor 0.5 save im in f2 end tell === page 399b === property fieldnames : {"firstname", "lastname", "book"} property theData : {{"Matt", "Neuburg", "AppleScript"}, {"Charles", "Dickens", "Pickwick"}, {"William", "Shakespeare", "Hamlet"}} tell application "Database Events" set d to (make new database with properties {name:"people"}) tell d repeat with i from 1 to (count theData) set r to (make new record with properties {name:""}) repeat with j from 1 to (count fieldnames) tell r to make new field with properties {name:item j of fieldnames, value:item j of item i of theData} end repeat end repeat save end tell delete every database -- actually, just closes the database end tell === page 399c === tell application "Database Events" tell database "~/Documents/Databases/people.dbev" get value of field "book" of (every record where value of field "firstname" is "Matt") -- "AppleScript" end tell end tell === page 400a === set d to space & "~/Desktop/people.db" & space set s to "sqlite3" & d & quote set s to s & "create table people(firstname, lastname, book); " set s to s & "insert into people values('matt','neuburg','AppleScript'); " set s to s & "insert into people values('charles','dickens','Pickwick'); " set s to s & "insert into people values('william', 'shakespeare', 'Hamlet');" set s to s & quote do shell script s === page 400b === set d to space & "~/Desktop/people.db" & space set s to "sqlite3 -list" & d & quote set s to s & "select book from people where firstname = 'matt';" set s to s & quote do shell script s -- "AppleScript" === page 403 === tell application "TextEdit" to activate tell application "System Events" tell application process "TextEdit" tell menu 1 of menu bar item "Format" of menu bar 1 click menu item 4 end tell end tell end tell === page 405a === tell application "System Preferences" activate set current pane to pane "com.apple.preferences.sharing" end tell tell application "System Events" tell application process "System Preferences" tell tab group 1 of window "Sharing" click radio button "Services" select row 1 of table 1 of scroll area 1 click button 1 end tell end tell end tell === page 405b === tell application "TextEdit" to activate -- front window contains this is a test of GUI scripting; test is selected tell application "System Events" tell application process "TextEdit" tell window 1 tell text area 1 of scroll area 1 get value of attribute "AXSelectedText" -- "test" get value of attribute "AXSelectedTextRange" -- {11,14} end tell end tell end tell end tell === page 405c === tell application "TextEdit" activate close window 1 end tell tell application "System Events" tell application process "TextEdit" tell window 1 repeat while not (exists sheet 1) delay 0.5 end repeat click button "Dont Save" of sheet 1 end tell end tell end tell === page 406 === set s to text returned of (display dialog "Word to define:" default answer "") -- prestidigitation tell application "Dictionary" to activate open location "DICT:///" & (s as string) tell application "System Events" tell application process "Dictionary" tell UI element 1 of scroll area 1 of scroll area 1 of group 1 of window 1 set s to value of it end tell end tell end tell s === page 408 === set theNum to text returned of (display dialog "Enter a number:" default answer "") set s to "printf %X " & theNum display dialog (do shell script s) === page 409a === set theNum to text returned of (display dialog "Enter a number:" default answer "") set t to path to temporary items set posixT to POSIX path of t set f to open for access file ((t as string) & "bctemp") with write permission write "obase = 16\n" to f write (theNum as string) & "\n" to f write "quit\n" to f close access f set s to "/usr/bin/bc " & quoted form of (posixT & "bctemp") display dialog (do shell script s) === page 409b === $s = ""; while (<>) { $s .= $_; } $s =~ m{search results (.*)$}si; $1 =~ m{}si; @rows = ($1 =~ m{}sig); for ($i=0;$i<$#rows;$i++) { ($links[$i], $titles[$i]) = ($rows[$i+1] =~ m{(.*?)}i); } print join "\n", @links, @titles; === page 410 === set t to text returned of (display dialog "Search TidBITS for:" default answer "") set text item delimiters to "+" set t to (words of t) as string set d to "'-response=TBSearch.lasso&-token.srch=TBAdv" set d to d & "&Article+HTML=" & t set d to d & "&Article+Author=&Article+Title=&-operator" set d to d & "=eq&RawIssueNum=&-operator=equals&ArticleDate" set d to d & "=&-sortField=ArticleDate&-sortOrder=descending" set d to d & "&-maxRecords=20&-nothing=MSExplorerHack&-nothing" set d to d & "=Start+Search' " set u to "http://db.tidbits.com/TBSrchAdv.lasso" set f to POSIX path of file ((path to temporary items as string) & "tempTidBITS") do shell script "curl -d " & d & " -o " & f & " " & u set perlScript to ... -- where is the Perl script? set r to do shell script "perl " & perlScript & " " & f set L to paragraphs of r set half to (count L) / 2 set L1 to items 1 thru half of L set L2 to items (half + 1) thru -1 of L set choice to (choose from list L2) as string repeat with i from 1 to half if item i of L2 is choice then open location (item i of L1) exit repeat end if end repeat === page 411a === set perlScript to quoted form of POSIX path of (path to resource "parseHTML.pl") === page 411b === % osalang -l === page 412a === % osascript -e $'tell app "Finder"\rdisplay dialog "Hello, world!"\rend' === page 412b === % osascript -e 'tell app "Finder"' -e 'display dialog "Hello, world!"' -e 'end' === page 413a === % osascript -ss -e 'tell app "Finder" to get name of every disk' === page 413b === % osascript -e 'tell app "Finder" to get name of every disk' === page 413c === % osascript -e '{"Mannie", {"Moe"}}' === page 413d === % osascript -e 'tell app "Address Book" to get name of every person' | tr , "\n" | sort -bf -k2 | uniq -d === page 413e === % osascript -e 'set pep to "Manny" & return & "Moe"' === page 413f === % osascript -e 'set pep to "Manny" & (ASCII character 10) & "Moe"' === page 413g === % osascript -e 'set pep to "Manny" & return & "Moe"' | tr "\r" "\n" === page 414a === % cat > textfile.txt on run what set total to 0 repeat with anItem in what set total to total + anItem end return total end ^D % osascript textfile.txt 1 2 3 === page 414b === $s = `osascript -e "tell app \\"Finder\\" to get name of every disk"`; === page 414c === $howdy = 'tell app "Finder" display dialog "howdy" end'; `osascript -e '$howdy'`; === page 414d === #!/usr/bin/perl $s = <<"END_S"; tell application "Finder" count disks end tell END_S chomp ($numDisks = `osascript -ss -e '$s'`); print "You have $numDisks disks.\n", "Which one would you like to know the name of?\n", "Type a number between 1 and $numDisks: "; while (<>) { chomp; last if $_ < 1 || $_ > $numDisks; $ss = <<"END_SS"; tell application "Finder" get name of disk $_ end tell END_SS print `osascript -ss -e '$ss'`, "Type a number between 1 and $numDisks: "; } === page 415 === #!/usr/bin/ruby class Histogram def initialize @tally = Hash.new(0) end def analyze(s) s.split.each do |word| myword = word.downcase.gsub(/[^a-z0-9]/, "") @tally[myword] = @tally[myword] + 1 if !myword.empty? end @tally.sort { |x,y| y[1]<=>x[1] } end end analysis = Histogram.new.analyze(File.new(ARGV[0]).read) counter = 1 oneline = "" analysis[0..29].each do |entry| oneline = oneline + "set the value of cell 1 of " + "row #{counter.to_s} to \"#{entry[0]}\"\n" oneline = oneline + "set the value of cell 2 of " + "row #{counter.to_s} to #{entry[1].to_s}\n" counter = counter + 1 end script = <" & whatName & ": " & whatValue & "

" & return end makeLine on addLine(whatName, whatValue) set s to s & makeLine(whatName, whatValue) end addLine on handle CGI request path_args from virtual host virtual_host searching for http_search_args with posted data post_args using access method method from address client_address from user username using password pword with user info from_user from server server_name via port server_port executing by script_name of content type content_type referred by referer from browser user_agent of action type action_path from client IP address client_ip with full request full_request with connection ID connection_id using action action set s to http_header set s to s & "Echo Page" & return set s to s & "

Echo Page

" & return addLine("virtual_host", POSIX path of virtual_host) addLine("path_args", path_args) addLine("http_search_args", http_search_args) addLine("post_args", post_args) addLine("method", method) addLine("client_address", client_address) addLine("username", username) addLine("password", pword) addLine("from_user", from_user) addLine("server_name", server_name) addLine("server_port", server_port) addLine("script_name", script_name) addLine("content_type", content_type) addLine("referer", referer) addLine("user_agent", user_agent) addLine("action_path", action_path) addLine("client_ip", client_ip) addLine("full_request", "

" & full_request & "

") addLine("connection_ID", connection_id) addLine("action", action) set s to s & "


" & (current date) & "" set s to s & "" return s end handle CGI request === page 428 === tell application "UI Actions" tell UI action "Script Editor-AXWindowCreated" set d to date string of (get timestamp) set w to affected UI element end tell end tell tell application "System Events" set n to title of w if n begins with "Untitled" then tell application "Script Editor" set text of document n to "-- " & d end tell end if end tell === page 433 === on run display dialog "Howdy!" end run on reopen display dialog "Get to Work!" end reopen on quit display dialog "Farewell!" continue quit end quit on idle beep activate display dialog "Get to Work!" return 1 * minutes end idle === page 434 === global shouldQuit global didCleanup on run set shouldQuit to false set didCleanup to false try -- lengthy operation goes here repeat with x from 1 to 10 if shouldQuit then error say (x as string) delay 5 end repeat on error tell me to quit end try end run on quit if not didCleanup then -- cleanup operation goes here say "cleaning up" set didCleanup to true end if set shouldQuit to true continue quit end quit === page 435a === on open what set total to 0 repeat with f in what if folder of (info for f size no) then set total to total + 1 end repeat display dialog (total as string) & " folder(s)" end open === page 435b === property total : 0 on open what repeat with f in what if folder of (info for f size no) then set total to total + 1 end repeat display dialog (total as string) & " folder(s)" end open === page 436 === set thePath to (path to resource "applet.icns") as string set text item delimiters to ":" set thePath to ((text items 1 thru -2 of thePath) as string) & ":myPrefs.scpt" script myPrefs property favoriteColor : "" end script try set myPrefs to load script file thePath on error set favoriteColor of myPrefs to text returned of (display dialog "Favorite Color:" default answer "" buttons {"OK"} default button "OK") store script myPrefs in file thePath replacing yes end try display dialog "Your favorite color is " & favoriteColor of myPrefs === For the SearchTidBITS example developed in Chapter 27: === For the Lame Encode example developed in Chapter 27: === For the Pairs scriptable Cocoa application developed in Chapter 27: === page 503 === on pad(s) repeat while length of s < 2 set s to ("0" & s) end repeat return s end pad on bust(s) set text item delimiters to ":" set pathParts to text items of s set text item delimiters to "." set nameParts to text items of last item of pathParts return {pathParts, nameParts} end bust on rename(n1, n2, oldPath) set bothLists to bust(oldPath) set extension to last item of item 2 of bothLists set pathPart to items 1 thru -2 of item 1 of bothLists set newFileName to "as_" & pad(n1) & pad(n2) set newFileName to newFileName & "." & extension set text item delimiters to ":" return (pathPart as string) & ":" & newFileName end rename on justName(s) set text item delimiters to ":" return last text item of s end justName on writeInfo(n1, n2, theName, theTitle) set s to return & n1 & "-" & n2 & tab & theName & tab & theTitle & return set f to open for access file "feathers:Users:mattneub:figs" with write permission write s to f starting at (get eof of f) close access f end writeInfo tell application "FrameMaker 7.0" tell document "gromit:Users:matt2:extra:astdg:appa" tell text flow 1 set howMany to count (get tables whose table tag is "Figure") set chapNum to (get paragraph number of paragraphs whose paragraph tag is "ChapterLabel") end tell set chapNum to word -1 of item 1 of chapNum set allPaths to {} select paragraph 1 of text flow 1 set counter to 1 repeat howMany times set oneTable to find table having tag with value "Figure" in it set thisFile to inset file of inset 1 of anchored frame 1 of paragraph 1 of cell 1 of oneTable set newName to my rename(chapNum, (counter as string), thisFile) set newShortName to my justName(newName) tell application "Finder" to set name of file thisFile to newShortName set inset file of inset 1 of anchored frame 1 of paragraph 1 of cell 1 of oneTable to newName set theTitle to text from character 2 to -1 of (get title of oneTable) my writeInfo(chapNum, (counter as string), newShortName, theTitle) select insertion point after selection set counter to counter + 1 end repeat end tell end tell === page 509 === [[NSWorkspace sharedWorkspace] launchApplication:@"BBEdit"]; NSAppleEventDescriptor* bbedit = [NSAppleEventDescriptor descriptorWithDescriptorType:typeApplicationBundleID data:[@"com.barebones.bbedit" dataUsingEncoding:NSUTF8StringEncoding]]; NSAppleEventDescriptor* ae = [NSAppleEventDescriptor appleEventWithEventClass:'core' eventID:'crel' targetDescriptor:bbedit returnID:kAutoGenerateReturnID transactionID:kAnyTransactionID]; [ae setParamDescriptor:[NSAppleEventDescriptor descriptorWithTypeCode:'docu'] forKeyword:'kocl']; AESendMessage([ae aeDesc], NULL, kAENoReply | kAENeverInteract, kAEDefaultTimeout); ae = [NSAppleEventDescriptor appleEventWithEventClass:'core' eventID:'setd' targetDescriptor:bbedit returnID:kAutoGenerateReturnID transactionID:kAnyTransactionID]; [ae setParamDescriptor: [NSAppleEventDescriptor descriptorWithString:@"Hello, world!"] forKeyword:'data']; AEDesc docu1; CreateObjSpecifier('docu', [[NSAppleEventDescriptor nullDescriptor] aeDesc], formAbsolutePosition, [[NSAppleEventDescriptor descriptorWithInt32:1] aeDesc], YES, &docu1); AEDesc allText; CreateObjSpecifier('ctxt', &docu1, formAbsolutePosition, [[NSAppleEventDescriptor descriptorWithDescriptorType: 'abso' bytes:"all " length:4] aeDesc], YES, &allText); NSAppleEventDescriptor* allTextDesc = [[NSAppleEventDescriptor alloc] initWithAEDescNoCopy:&allText]; [ae setParamDescriptor:allTextDesc forKeyword:keyDirectObject]; AESendMessage([ae aeDesc], NULL, kAENoReply | kAENeverInteract, kAEDefaultTimeout); === page 510 === dim ae as AppleEvent dim theDoc, theText as AppleEventObjectSpecifier dim s as new shell s.execute("open -a 'BBEdit'") ae = NewAppleEvent("core","crel", "R*ch") ae.macTypeParam("kocl") = "docu" call ae.send theDoc = getIndexedObjectDescriptor("docu", nil, 1) theText = getOrdinalObjectDescriptor("ctxt",theDoc,"all ") ae = NewAppleEvent("core","setd","R*ch") ae.objectSpecifierParam("----") = theText ae.stringParam("data") = "Hello, world!" call ae.send === page 511 === with (MacOS.appBySignature("R*ch")) { make(_types.document); document[1].valueOf().text = "Hello, world!"; } === page 512 === if !(bbedit.isRunning()) launch.application(bbedit.appinfo.path) with objectmodel, bbedit make(document) set(document[1].text,"Hello, world!") === page 514a === use Mac::Glue; my $bb = Mac::Glue->new('BBEdit'); $bb->launch(); $bb->make(new => 'document'); my $doc = $bb->obj(document => 1); my $text = $bb->obj(property => 'text', $doc); $bb->set($text, to => 'Hello, world!'); === page 514b === from appscript import * bb = app('BBEdit') bb.make(new=k.document) bb.documents[1].text.set('Hello, world!') === pages 516-523 (URLs) === http://www.latenightsw.com http://www.latenightsw.com/freeware/JavaScriptOSA/ http://projects.pudge.net http://freespace.virgin.net/hamish.sanderson/appscript.html http://www.userland.comhttp://sourceforge.net/projects/frontierkernel http://homepage.mac.com/philip_aker/ http://applemods.sourceforge.net http://www.prefab.com/uibrowser/ http://www.realbasic.com http://pan.uqam.ca/pan/pmwiki.php/Pan/HomePage http://www.mcgath.com/EightyRez.html http://www.satimage.fr/software/en/softx.html http://www.red-sweater.com/RedSweater/FSFeatures.html http://ranchero.com/bigcat http://www.xendai.com/bellhop/ http://www.sentman.com/acgi/ http://www.startly.com/products/qkx.html http://www.prefab.com/player.html http://www.scriptsoftware.com/ikey http://www.keyboardmaestro.comhttp://www.dragthing.com http:// www.appsandmore.com http://www.sophisticated.com/products/ido/ido_ss.html http://www.prefab.com/uiactions/ http://www.latenightsw.com/freeware/RecordTools/ http://www.seanet.com/~jonpugh/ http://www.barebones.com/products/bbedit/ http://www.creatorsoftware.com/products/ http://www.barebones.com/products/mailsmith/ http://www.eudora.com/email/ http://www.microsoft.com/macoffice/ http://www.filemaker.com http://www.lemkesoft.com/en/graphcon.htm http://www.tex-edit.com http://www.aquaminds.com http://www.stuffit.com/mac/ http://c-command.com http://www.salling.com/Clicker/ http://www.ovolab.com/phlink/ http://freespace.virgin.net/hamish.sanderson/ http://www.adobe.com/products/framemaker/main.html http://www.apple.com/applescript/ http://developer.apple.com/documentation/AppleScript/Conceptual/AppleScriptX/ http://developer.apple.com/documentation/AppleScript/Conceptual/AppleScriptLangGuide/ http://www.applescriptsourcebook.com/applescript.html http://developer.apple.com/documentation/mac/IAC/IAC-308.html http://developer.apple.com/documentation/Cocoa/Conceptual/Scriptability/Tasks/SuiteDefs.html http://www.apple.com/applescript/uiscripting/ http://developer.apple.com/documentation/AppleScript/Conceptual/StudioBuildingApps/index.html http://developer.apple.com/techpubs/macosx/Cocoa/TasksAndConcepts/ProgrammingTopics/Scriptability/Concepts/ScriptingOnOSX.html http://developer.apple.com/documentation/AppleScript/Conceptual/soapXMLRPC/ http://developer.apple.com/documentation/mac/IAC/IAC-2.html http://developer.apple.com/documentation/Carbon/Reference/Apple_Event_Manager/ http://developer.apple.com/documentation/AppleScript/Conceptual/AppleEvents/ http://developer.apple.com/documentation/Carbon/Reference/Open_Scripti_Architecture/index.html http://www.cs.utexas.edu/users/wcook/papers/AppleScript/AppleScript95.pdf http://developer.apple.com/documentation/Cocoa/Conceptual/Scriptability/Concepts/ScriptabilityTerms.html http://developer.apple.com/technotes/tn/tn1164.html http://www.mactech.com/articles/mactech/Vol.10/10.01/ExtendApplescript/ http://www.latenightsw.com/technotes/ScriptingAddition/ http://www.satimage.fr/software/en/downloads_sample_projects.html http://developer.apple.com/documentation/Cocoa/Conceptual/Scriptability/ http://developer.apple.com/documentation/Cocoa/Conceptual/ScriptableCocoaApplications http://developer.apple.com/technotes/tn2002/tn2106.html http://developer.apple.com/samplecode/Sketch-112/Sketch-112.html http://chezjd.free.fr/Creation/logiciel.php?sign=SdEd http://www.stone.com/The_Cocoa_Files/Adding_Applescript.html http://cocoadev.com/?HowToSupportAppleScript http://homepage.mac.com/donbriggs/ http://www.scriptweb.org http://macscripter.net http://osaxen.com http://www.applescriptsourcebook.com/home.html http://www.xmethods.net http://lists.apple.com/mailman/listinfo/applescript-users http://www.lsoft.com/scripts/wl.exe?SL1=MACSCRPT&H=LISTSERV.DARTMOUTH.EDU http://lists.apple.com/mailman/listinfo/applescript-implementors http://lists.apple.com/mailman/listinfo/applescript-studio http://www.dannyg.com/pubs/index.html http://www.amazon.com/exec/obidos/ASIN/0201353598/ http://www.amazon.com/exec/obidos/ASIN/0201716135 http://www.amazon.com/exec/obidos/ASIN/0970726511/ http://www.amazon.com/exec/obidos/ASIN/0970726503/ http://www.amazon.com/exec/obidos/ASIN/0321112512/ http://www.oreilly.com/catalog/ltigerunix/ http://www.oreilly.com/catalog/pperl3/ http://www.oreilly.com/catalog/python2/ http://www.rubycentral.com/book/