AppleScript_ The Definitive Guide - Matt Neuburg [201]
Example
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"}
Name
get eof
Synopsis
get file end position
get file end position
Returns the index of the last character of a file (which is also the size of the file). Because character position values start at 1, and because the eof is the position of the last character, if you want to append to a file you must start writing at a position one greater than the eof (and that is the largest position at which you are permitted to start writing).
Example
write "Howdy" to f
set ourEof to get eof of f
write "Doody" to f starting at ourEof + 1
Name
set eof
Synopsis
set file end position
set file end position
Sets a file's size, truncating its data or filling the new excess with zeros. To replace an existing file's data, set its eof to 0 before writing to it.
Name
close access
Synopsis
close file
close file
Closes a file. Always close a file you have opened for access!
Name
ASCII character
Synopsis
number to character
number to character
Converts an ASCII numeric value to a one-character (MacRoman) string.
Example
ASCII character 82 -- "R"
Name
ASCII number
Synopsis
character to number
character to number
Converts the first character of a (MacRoman) string to an ASCII numeric value.
Example
ASCII number "Ribbit" -- 82
Name
offset
Synopsis
substring position
substring position
Reports the position of a substring within a target string. Character position values start at 1. Returns 0 if the substring isn't found. Formerly considered case and ignored diacriticals, which is backwards from AppleScript's own defaults; staring in Panther, this is fixed, and string considerations are obeyed (see "String Considerations" in Chapter 19).
Example
offset of "bb" in "Ribbit" -- 3
Name
summarize
Synopsis
summary of content
summary of content
Summarizes the content of a string or textfile, like the Summarize Service.
Name
set the clipboard to
Synopsis
set clipboard
set clipboard
Puts data onto the clipboard.
Name
clipboard info
Synopsis
describe clipboard
describe clipboard
Describes the contents of the clipboard as a list of class-size pairs.
Example
-- user has copied a file's icon in the Finder
clipboard info
-- {{string, 20}, {«class ut16», 44}, {«class hfs », 80}, {«class
utf8», 20}, {Unicode text, 42}, {picture, 2616}, {«class icns», 43336},
{«class furl», 62}}
Name
the clipboard
Synopsis
get clipboard
get clipboard
Gets the clipboard text, or you can specify some other class. A common trick is to specify as record; in the resulting record, the names of the items are their classes, and the values are their values.
-- user has copied a file's 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
Name
round
Synopsis
round
round
Rounds a real to an integer, in various ways (one of which is called rounding as taught in school, showing that AppleScript has a sense of humor).
Example
round 1.3 -- 1
Name
random number
Synopsis
generate random number
generate random number
Generates a random number. By default, this is a real between 0 and 1, but you can specify a different upper bound or both bounds. If every