This chapter describes the commands available to perform actions in AppleScript scripts. For information on how commands work, see “Commands Overview”.
The commands described in this chapter are available to any script—they are either built into the AppleScript language or added to it through the standard scripting additions (described in “Scripting Additions”).
Note: In the command descriptions below, if the first item in the Parameters list does not include a parameter name, it is the direct parameter of the command (described in “Direct Parameter”).
Table 7-1 lists each command according to the suite (or related group) of commands to which it belongs and provides a brief description. Detailed command descriptions follow the table, in alphabetical order.
Command | Description |
|---|---|
Brings an application to the front, and opens it if it is on the local computer and not already running. | |
In Script Editor, displays a value in the Event Log History window or in the Event Log pane of a script window. | |
Returns information about the clipboard. | |
Places data on the clipboard. | |
Returns the contents of the clipboard. | |
Returns information for a file or folder. | |
Returns a list of the currently mounted volumes. Deprecated Use | |
Returns the contents of a specified folder. Deprecated Use | |
Mounts the specified AppleShare volume. | |
Returns the full path to the specified application. | |
Returns the full path to the specified folder. | |
Returns the full path to the specified resource. | |
Closes a file that was opened for access. | |
Returns the length, in bytes, of a file. | |
Reads data from a file that has been opened for access. | |
Sets the length, in bytes, of a file. | |
Writes data to a file that was opened for access with write permission. | |
Opens a URL with the appropriate program. | |
Returns the current date and time. | |
Executes a shell script using the | |
Returns the sound output and input volume settings. | |
Generates a random number. | |
Rounds a number to an integer. | |
Sets the sound output and/or input volume. | |
Gets environment variables or attributes of this computer. | |
Returns information about the system. | |
Returns the difference between local time and GMT (Universal Time). | |
Returns a | |
Runs a script or script file | |
Returns a list of all scripting components. | |
Stores a | |
Copies one or more values into variables. | |
Counts the number of elements in an object. | |
Returns the value of a script expression or an application object. | |
Launches the specified application without sending it a | |
For an application, launches it. For a script application, launches it and sends it the | |
Assigns one or more values to one or more script variables or application objects. | |
Converts a number to a character. Deprecated starting in AppleScript 2.0. Use the | |
Converts a character to its numeric value. Deprecated starting in AppleScript 2.0. Use the | |
Returns the localized string for the specified key. | |
Finds one piece of text inside another. | |
Summarizes the specified text or text file. | |
Beeps one or more times. | |
Allows the user to choose an application. | |
Allows the user to choose a color. | |
Allows the user to choose a file. | |
Allows the user to specify a new file reference. | |
Allows the user to choose a folder. | |
Allows the user to choose one or more items from a list. | |
Allows the user to choose a running application on a remote machine. | |
Allows the user to specify a URL. | |
Pauses for a fixed amount of time. | |
Displays an alert. | |
Displays a dialog box, optionally requesting user input. | |
Speaks the specified text. |
Brings an application to the front, launching it if necessary.
activate |
application | required | |
The application to activate.
None.
activate application "TextEdit" |
tell application "TextEdit" to activate |
The activate command does not launch applications on remote machines. For examples of other ways to specify an application, see the application class and “Remote Applications”.
Returns the character for a specified number.
Important: This command is deprecated starting in AppleScript 2.0—use the id property of the text class instead.
ASCII character |
integer | required | |
The character code, an integer between 0 and 255.
A text object containing the character that corresponds to the specified number.
Signals an error if integer is out of range.
set theChar to ASCII character 65 --result: "A" |
set theChar to ASCII character 194 --result: "¬" |
set theChar to ASCII character 2040 --result: invalid range error |
The name “ASCII” is something of a misnomer. ASCII character uses the primary text encoding, as determined by the user’s language preferences, to map between integers and characters. If the primary language is English, the encoding is Mac OS Roman, if it is Japanese, the encoding is MacJapanese, and so on. For integers below 128, this is generally the same as ASCII, but for integers from 128 to 255, the results vary considerably.
Because of this unpredictability, ASCII character and ASCII number are deprecated starting in AppleScript 2.0. Use the id property of the text class instead, since it always uses the same encoding, namely Unicode.
Returns the number associated with a specified character.
Important: This command is deprecated starting in AppleScript 2.0—use the id property of the text class instead.
ASCII number |
text | required | |
A text object containing at least one character. If there is more than one character, only the first one is used.
The character code of the specified character as an integer.
set codeValue to ASCII number "¬" --result: 194 |
The result of ASCII number depends on the user’s language preferences; see the Discussion section of ASCII character for details.
Plays the system alert sound one or more times.
beep |
required | ||
|
integer | optional | |
Number of times to beep.
1
None.
Audible alerts can be useful when no one is expected to be looking at the screen:
beep 3 --result: three beeps, to get attention |
display dialog "Something is amiss here!" -- to show message |
Allows the user to choose an application.
choose application |
required | ||
with title |
text | optional | |
with prompt |
text | optional | |
multiple selections allowed |
boolean | optional | |
as |
class | optional | |
with title textTitle text for the dialog.
"Choose Application"
with prompt text A prompt to be displayed in the dialog.
"Select an application:"
multiple selections allowed boolean Allow multiple items to be selected? If true, the results will be returned in a list, even if there is exactly one item.
false
as class (application | alias)Specifies the desired class of the result. If specified, the value must be one of application or alias.
application
The selected application, as either an application or alias object; for example, application "TextEdit". If multiple selections are allowed, returns a list containing one item for each selected application, if any.
Signals a “user canceled” error if the user cancels the dialog. For an example of how to handle such errors, see “try Statements”.
choose application with prompt "Choose a web browser:" |
choose application with multiple selections allowed |
choose application as alias |
The choose application dialog initially presents a list of all applications registered with the system. To choose an application not in that list, use the Browse button, which allows the user to choose an application anywhere in the file system.
Allows the user to choose a color from a color picker dialog.
choose color |
required | ||
default color |
RGB color | optional | |
default color RGB colorThe color to show when the color picker dialog is first opened.
{0, 0, 0}: black.
The selected color, represented as a list of three integers from 0 to 65535 corresponding to the red, green, and blue components of a color; for example, {0, 65535, 0} represents green.
Signals a “user canceled” error if the user cancels the choose color dialog. For an example of how to handle such errors, see “try Statements”.
This example lets the user choose a color, then uses that color to set the background color in their home folder (when it is in icon view):
tell application "Finder" |
tell icon view options of window of home |
choose color default color (get background color) |
set background color to the result |
end tell |
end tell |
Allows the user to choose a file.
with prompt textThe prompt to be displayed in the dialog.
None; no prompt is displayed.
of type list of textA list of Uniform Type Identifiers (UTIs); for example, {"public.html", "public.rtf"}. Only files of the specified types will be selectable. For a list of system-defined UTIs, see Uniform Type Identifiers Overview. To get the UTI for a particular file, use info for.
Note: Four-character file type codes, such as "PICT" or "MooV", are also supported, but are deprecated. To get the file type code for a particular file, use info for.
None; any file can be chosen.
default location aliasThe folder to begin browsing in.
Browsing begins in the last selected location, or, if this is the first invocation, in the user’s Documents folder.
invisibles booleanShow invisible files and folders?
true: This is only for historical compatibility reasons. Unless you have a specific need to choose invisible files, you should always use invisibles false.
multiple selections allowed booleanAllow multiple items to be selected? If true, the results will be returned in a list, even if there is exactly one item.
false
showing package contents booleanShow the contents of packages? If true, packages are treated as folders, so that the user can choose a file inside a package (such as an application).
false. Manipulating the contents of packages is discouraged unless you control the package format or the package itself.
The selected file, as an alias. If multiple selections are allowed, returns a list containing one alias for each selected file, if any.
Signals a “user canceled” error if the user cancels the dialog. For an example of how to handle such errors, see “try Statements”.
set aFile to choose file with prompt "HTML or RTF:" ¬ |
of type {"public.html", "public.rtf"} invisibles false |
A UTI can specify a general class of files, not just a specific format. The following script allows the user to choose any image file, whether its format is JPEG, PNG, GIF, or whatever. It also uses the default location parameter combined with path to (folder) to begin browsing in the user’s Pictures folder:
set picturesFolder to path to pictures folder |
choose file of type "public.image" with prompt "Choose an image:" ¬ |
default location picturesFolder invisibles false |
Allows the user to specify a new filename and location. This does not create a file—rather, it returns a file specifier that can be used to create a file.
choose file name |
required | ||
with prompt |
text | optional | |
default name |
text | optional | |
default location |
alias | optional | |
with prompt textThe prompt to be displayed near the top of the dialog.
"Specify new file name and location"
default name textThe default file name.
"untitled"
default location aliasThe default file location. See choose file for examples.
Browsing starts in the last location in which a search was made or, if this is the first invocation, in the user’s Documents folder.
The selected location, as a file. For example:
file "HD:Users:currentUser:Documents:untitled"
Signals a “user canceled” error if the user cancels the dialog. For an example of how to handle such errors, see “try Statements”.
The following example supplies a non-default prompt and search location:
set fileName to choose file name with prompt "Save report as:" ¬ |
default name "Quarterly Report" ¬ |
default location (path to desktop folder) |
If you choose the name of a file or folder that exists in the selected location, choose file name offers the choice of replacing the chosen item. However, choosing to replace does not actually replace the item.
Allows the user to choose a directory, such as a folder or a disk.
choose folder |
required | ||
with prompt |
text | optional | |
default location |
alias | optional | |
invisibles |
boolean | optional | |
multiple selections allowed |
boolean | optional | |
showing package contents |
boolean | optional | |
with prompt textThe prompt to be displayed in the dialog.
None; no prompt is displayed.
default location aliasThe folder to begin browsing in.
Browsing begins in the last selected location, or, if this is the first invocation, in the user’s Documents folder.
invisibles booleanShow invisible folders?
false
multiple selections allowed booleanAllow multiple items to be selected? If true, the results will be returned in a list, even if there is exactly one item.
false
showing package contentsbooleanShow the contents of packages? If true, packages are treated as folders, so that the user can choose a package folder, such as an application, or a folder inside a package.
false. Manipulating the contents of packages is discouraged unless you control the package format or the package itself.
The selected directory, as an alias. If multiple selections are allowed, returns a list containing one alias for each selected directory, if any.
Signals a “user canceled” error if the user cancels the choose folder dialog. For an example of how to handle such errors, see “try Statements”.
The following example specifies a prompt and allows multiple selections:
set foldersList to choose folder ¬ |
with prompt "Select as many folders as you like:" ¬ |
with multiple selections allowed |
The following example gets a POSIX path to a chosen folder and uses the quoted form property (of the text class) to ensure correct quoting of the resulting string for use with shell commands:
set folderName to quoted form of POSIX path of (choose folder) |
Suppose that you choose the folder named iWork '08 in your Applications folder. The previous statement would return the following result, which properly handles the embedded single quote and space characters in the folder name:
"'/Applications/iWork '\\''08/'" |
Allows the user to choose items from a list.
A list of numbers and/or text objects for the user to choose from.
with title textTitle text for the dialog.
None; no title is displayed.
with prompt textThe prompt to be displayed in the dialog.
"Please make your selection:"
default items list (of number or text)A list of numbers and/or text objects to be initially selected. The list cannot include multiple items unless you also specify multiple selections allowed true. If an item in the default items list is not in the list to choose from, it is ignored.
None; no items are selected.
OK button name textThe name of the OK button.
"OK"
cancel button name textThe name of the Cancel button.
"Cancel"
multiple selections allowed booleanAllow multiple items to be selected?
false
empty selection allowed booleanAllow the user to choose OK with no items selected? If false, the OK button will not be enabled unless at least one item is selected.
false
If the user clicks the OK button, returns a list of the chosen number and/or text items; if empty selection is allowed and nothing is selected, returns an empty list ({}). If the user clicks the Cancel button, returns false.
This script selects from a list of all the people in Address Book who have defined birthdays, and gets the birthday of the selected one. Notice the if the result is not false test (choose from list returns false if the user clicks Cancel) and the set aName to item 1 of the result (choose from list returns a list, even if it contains only one item).
tell application "Address Book" |
set bDayList to name of every person whose birth date is not missing value |
choose from list bDayList with prompt "Whose birthday would you like?" |
if the result is not false then |
set aName to item 1 of the result |
set theBirthday to birth date of person named aName |
display dialog aName & "'s birthday is " & date string of theBirthday |
end if |
end tell |
For historical reasons, choose from list is the only dialog command that returns a result (false) instead of signaling an error when the user presses the “Cancel” button.
Allows the user to choose a running application on a remote machine.
choose remote application |
required | ||
with title |
text | optional | |
with prompt |
text | optional | |
with title textTitle text for the choose remote application dialog.
None; no title is displayed.
with prompt textThe prompt to be displayed in the dialog.
"Select an application:"
The selected application, as an application object.
Signals a “user canceled” error if the user cancels the dialog. For an example of how to handle such errors, see “try Statements”.
set myApp to choose remote application with prompt "Choose a remote web browser:" |
The user may choose a remote machine using Bonjour or by entering a specific IP address. There is no way to limit the precise kind of application returned, so either limit your script to generic operations or validate the user’s choice. If you want your script to send application-specific commands to the resulting application, you will need a using terms from statement.
For information on targeting other machines, see “Remote Applications”.
Allows the user to specify a URL.
choose URL |
required | ||
showing |
listOfServiceTypesOrTextStrings | optional | |
editable URL |
boolean | optional | |
showing list (of service types or text)A list that specifies the types of services to show, if available. The list can contain one or more of the following service types, or one or more text objects representing Bonjour service types (described below), or both:
Web servers: shows http and https services
FTP Servers: shows ftp services
Telnet hosts: shows telnet services
File servers: shows afp, nfs, and smb services
News servers: shows nntp services
Directory services: shows ldap services
Media servers: shows rtsp services
Remote applications: shows eppc services
A text object is interpreted as a Bonjour service type—for example, "_ftp._tcp" represents the file transfer protocol. These types are listed in Technical Q&A 1312: Bonjour service types used in Mac OS X.
File servers
editable URL booleanAllow user to type in a URL? If you specify editable URL false, the text field in the dialog is inactive.
choose URL does not attempt to verify that the user-entered text is a valid URL. Your script should be prepared to verify the returned value.
true: the user can enter a text string. If false, the user is restricted to choosing an item from the Bonjour-supplied list of services.
The URL for the service, as a text object. This result may be passed to open location or to any application that can handle the URL, such as a browser for http URLs.
Signals a “user canceled” error if the user cancels the dialog. For an example of how to handle such errors, see “try Statements”.
The following script asks the user to choose an URL, either by typing in the text input field or choosing one of the Bonjour-located servers:
set myURL to choose URL |
tell application Finder to open location myURL |
Returns information about the current clipboard contents.
clipboard info |
required | ||
for |
class | optional | |
for classRestricts returned information to only this data type.
None; returns information for all types of data as a list of lists, where each list represents a scrap flavor.
A list containing one entry {class, size} for each type of data on the clipboard. To retrieve the actual data, use the the clipboard command.
clipboard info |
clipboard info for Unicode text |
Closes a file opened with the open for access command.
close access |
fileSpecifier | required | |
The alias or file specifier or integer file descriptor of the file to close. A file descriptor must be obtained as the result of an earlier open for access call.
None.
Signals an error if the specified file is not open.
You should always close files that you open, being sure to account for possible errors while using the open file:
set aFile to choose file |
set fp to open for access aFile |
try |
--file reading and writing here |
on error e number n |
--deal with errors here and don't resignal |
end |
close access fp |
Any files left open will be automatically closed when the application exits.
Copies one or more values, storing the result in one or more variables. This command only copies AppleScript values, not application-defined objects.
copy |
expression | required | |
to |
variablePattern | required | |
The expression whose value is to be copied.
to variablePatternThe name of the variable or pattern of variables in which to store the value or pattern of values. Patterns may be lists or records.
The new copy of the value.
As mentioned in the Discussion, copy creates an independent copy of the original value, and it creates a deep copy. For example:
set alpha to {1, 2, {"a", "b"}} |
copy alpha to beta |
set item 2 of item 3 of alpha to "change" --change the original list |
set item 1 of beta to 42 --change a different item in the copy |
{alpha, beta} |
--result: {{1, 2, {"a", "change"}}, {42, 2, {"a", "b"}}} |
Each variable reflects only the changes that were made directly to that variable. Compare this with the similar example in set.
See the set command for examples of using variable patterns. The behavior is the same except that the values are copied.
The copy command may be used to assign new values to existing variables, or to define new variables. See “Declaring Variables with the copy Command” for additional details.
Using the copy command creates a new value that is independent of the original—a subsequent change to that value does not change the original value. The copy is a “deep” copy, so sub-objects, such as lists within lists, are also copied. Contrast this with the behavior of the set command.
When using copy with an object specifier, the specifier itself is the value copied, not the object in the target application that it refers to. copy therefore copies the object specifier, but does not affect the application data at all. To copy the object in the target application, use the application’s duplicate command, if it has one.
The syntax put expression into variablePattern is also supported, but is deprecated. It will be transformed into the copy form when you compile the script.
Counts the number of elements in another object.
(count | number of) |
expression | required | |
An expression that evaluates to an object with elements, such as a list, record, or application-defined container object. count will count the contained elements.
The number of elements, as an integer.
In its simplest form, count, or the equivalent pseudo-property number, counts the item elements of a value. This may be an AppleScript value, such as a list:
set aList to {"Yes", "No", 4, 5, 6} |
count aList --result: 5 |
number of aList --result: 5 |
…or an application-defined object that has item elements:
tell application "Finder" to count disk 1 --result: 4 |
If the value is an object specifier that evaluates to a list, count counts the items of that list. This may be an “Every” specifier:
count every integer of aList --result: 3 |
count words of "hello world" --result: 2 |
tell application "Finder" to count folders of disk 1 --result: 4 |
…or a “Filter” specifier:
tell application "Finder" |
count folders of disk 1 whose name starts with "A" --result: 1 |
end tell |
…or similar. For more on object specifiers, see “Object Specifiers”.
Returns the current date and time.
current date |
required | ||
The current date and time, as a date object.
current date --result: date "Tuesday, November 13, 2007 11:13:29 AM" |
See the date class for information on how to access the properties of a date, such as the day of the week or month.
Waits for a specified number of seconds.
delay |
required | ||
|
number | optional | |
The number of seconds to delay. The number may be fractional, such as 0.5 to delay half a second.
0
None.
set startTime to current date |
delay 3 --delay for three seconds |
set elapsedTime to ((current date) - startTime) |
display dialog ("Elapsed time: " & elapsedTime & " seconds") |
delay does not make any guarantees about the actual length of the delay, and it cannot be more precise than 1/60th of a second. delay is not suitable for real-time tasks such as audio-video synchronization.
Displays a standardized alert containing a message, explanation, and from one to three buttons.
The alert text, which is displayed in emphasized system font.
message textAn explanatory message, which is displayed in small system font, below the alert text.
as alertTypeThe type of alert to show. You can specify one of the following alert types:
informational: the standard alert dialog
warning: the alert dialog dialog is badged with a warning icon
critical: currently the same as the standard alert dialog
informational
buttons list (of text)A list of up to three button names.
If you supply one name, a button with that name serves as the default and is displayed on the right side of the alert dialog. If you supply two names, two buttons are displayed on the right, with the second serving as the default button. If you supply three names, the first is displayed on the left, and the next two on the right, as in the case with two buttons.
{"OK"}: One button labeled “OK”, which is the default button.
default button (text or integer)The name or number of the default button. This may be the same as the cancel button.
The rightmost button.
cancel button (text or integer)The name or number of the cancel button. See “Result” below. This may be the same as the default button.
None; there is no cancel button.
giving up after integer The number of seconds to wait before automatically dismissing the alert.
None; the dialog will wait until the user clicks a button.
If the user clicks a button that was not specified as the cancel button, display alert returns a record that identifies the button that was clicked—for example, {button returned: "OK"}. If the command specifies a giving up after value, the record will also contain a gave up:false item.
If the display alert command specifies a giving up after value, and the dialog is dismissed due to timing out before the user clicks a button, the command returns a record indicating that no button was returned and the command gave up: {button returned:"", gave up:true}
If the user clicks the specified cancel button, the command signals a “user canceled” error. For an example of how to handle such errors, see “try Statements”.
set alertResult to display alert "Insert generic warning here." ¬ |
buttons {"Cancel", "OK"} as warning ¬ |
default button "Cancel" cancel button "Cancel" giving up after 5 |
For an additional example, see the Examples section for the try statement.
Displays a dialog containing a message, one to three buttons, and optionally an icon and a field in which the user can enter text.
The dialog text, which is displayed in emphasized system font.
default answer textThe initial contents of an editable text field. This edit field is not present unless this parameter is present; to have the field present but blank, specify an empty string: default answer ""
None; there is no edit field.
hidden answer booleanIf true, any text in the edit field is obscured as in a password dialog: each character is displayed as a bullet.
false: text in the edit field is shown in cleartext.
buttons list (of text)A list of up to three button names.
If you don’t specify any buttons, by default, Cancel and OK buttons are shown, with the OK button set as the default button.
If you specify any buttons, there is no default or cancel button unless you use the following parameters to specify them.
default button (text | integer)The name or number of the default button. This button is highlighted, and will be pressed if the user presses the Return or Enter key.
If there are no buttons specified using buttons, the OK button. Otherwise, there is no default button.
cancel button (text | integer)The name or number of the cancel button. This button will be pressed if the user presses the Escape key or Command-period.
If there are no buttons specified using buttons, the Cancel button. Otherwise, there is no cancel button.
with title textThe dialog window title.
None; no title is displayed.
with icon (text | integer)The resource name or ID of the icon to display.
with icon (stop | note | caution)The type of icon to show. You may specify one of the following constants:
stop (or 0): Shows a stop icon
note (or 1): Shows the application icon
caution (or 2): Shows a warning icon, badged with the application icon
with icon (alias | file)An alias or file specifier that specifies a .icns file.
giving up after integerThe number of seconds to wait before automatically dismissing the dialog.
None; the dialog will wait until the user presses a button.
A record containing the button clicked and text entered, if any. For example:
{text returned:"Cupertino", button returned:"OK"}
If the dialog does not allow text input, there is no text returned item in the returned record.
If the user clicks the specified cancel button, the command signals a “user canceled” error. For an example of how to handle such errors, see “try Statements”.
If the display dialog command specifies a giving up after value, and the dialog is dismissed due to timing out before the user clicks a button, it returns a record indicating that no button was returned and the command gave up: {button returned:"", gave up:true}
The following example shows how to use many of the parameters to a display dialog command, how to process possible returned values, and one way to handle a user cancelled error. The dialog displays two buttons and prompts a user to enter a name, giving up if they do not make a response within fifteen seconds. It shows one way to handle the case where the user cancels the dialog, which results in AppleScript signaling an “error” with the error number -128. The script uses additional display dialog commands to show the flow of logic and indicate where you could add statements to handle particular outcomes.
set userCanceled to false |
try |
set dialogResult to display dialog ¬ |
"What is your name?" buttons {"Cancel", "OK"} ¬ |
default button "OK" cancel button "Cancel" ¬ |
giving up after 15 ¬ |
default answer (long user name of (system info)) |
on error number -128 |
set userCanceled to true |
end try |
if userCanceled then |
-- statements to execute when user cancels |
display dialog "User cancelled." |
else if gave up of dialogResult then |
-- statements to execute if dialog timed out without an answer |
display dialog "User timed out." |
else if button returned of dialogResult is "OK" then |
set userName to text returned of dialogResult |
-- statements to process user name |
display dialog "User name: " & userName |
end if |
end |
The following example displays a dialog that asks for a password. It supplies a default answer of "wrong", and specifies that the default answer, as well as any text entered by the user, is hidden (displayed as a series of bullets). It gives the user up to three chances to enter a correct password.
set prompt to "Please enter password:" |
repeat 3 times |
set dialogResult to display dialog prompt ¬ |
buttons {"Cancel", "OK"} default button 2 ¬ |
default answer "wrong" with icon 1 with hidden answer |
set thePassword to text returned of dialogResult |
if thePassword = "magic" then |
exit repeat |
end if |
end repeat |
if thePassword = "magic" or thePassword = "admin" then |
display dialog "User entered valid password." |
end if |
The password text is copied from the return value dialogResult. The script doesn’t check for a user cancelled error, so if the user cancels AppleScript stops execution of the script.
Executes a shell script using the sh shell.
do shell script |
text | required | |
as |
class | optional | |
administrator privileges |
boolean | optional | |
user name |
text | optional | |
password |
text | optional | |
altering line endings |
boolean | optional | |
The shell script to execute.
asclassSpecifies the desired type of the result. The raw bytes returned by the command will be interpreted as the specified class.
«class utf8»: UTF-8 text. If there is no as parameter and the output is not valid UTF-8, the output will be interpreted as text in the primary encoding.
administrator privileges booleanExecute the command as the administrator? Once a script is correctly authenticated, it will not ask for authentication again for five minutes. The elevated privileges and the grace period do not extend to any other scripts or to the rest of the system. For security reasons, you may not tell another application to do shell script with administrator privileges. Put the command outside of any tell block, or put it inside a tell me block.
false
user name textThe name of an administrator account. You can avoid a password dialog by specifying a name in this parameter and a password in the password parameter. If you specify a user name, you must also specify a password.
password textAn administrator password, typically used in conjunction with the administrator specified by the user name parameter. If user name is omitted, it is assumed to be the current user.
altering line endings booleanShould the do shell script command change all line endings in the command output to Mac-style and trim a trailing one? For example, the result of do shell script "echo foo; echo bar" is "foo\rbar", not the "foo\nbar\n" that the shell script actually returned.
true
The output of the shell script.
Signals an error if the shell script exits with a non-zero status. The error number will be the status, the error message will be the contents of stderr.
do shell script "uptime" |
For additional documentation and examples of the do shell script command, see Technical Note TN2065, do shell script in AppleScript.
Evaluates an object specifier and returns the result.
The command name get is typically optional—expressions that appear as statements or operands are automatically evaluated as if they were preceded by get. However, get can be used to force early evaluation of part of an object specifier.
get |
specifier | required | |
as |
class | optional | |
An object specifier to be evaluated. If the specifier refers to an application-defined object, the get command is sent to that application. Technically, all values respond to get, but for all values other than object specifiers, get is an identity operation: the result is the exact same value.
as classThe desired class for the returned data. If the data is not of the desired type, AppleScript attempts to coerce it to that type.
None; no coercion is performed.
The value of the evaluated expression. See “Reference Forms” for details on what the results of evaluating various object specifiers are.
get can get properties or elements of AppleScript-defined objects, such as lists:
get item 1 of {"How", "are", "you?"} --result: "How" |
…or of application-defined objects:
tell application "Finder" to get name of home --result: "myname" |