Name

store script

Syntax

store script scriptObject [in file path [replacing yes|no]]

Description

Saves scriptObject to disk as a compiled script file. Returns no value. If no further parameters are supplied, presents a Save File dialog; if the user cancels, a runtime error is raised. If path is supplied, presents no Save File dialog, but if the file exists already, presents a dialog asking how to proceed; if the user cancels, a runtime error is raised. If replacing is supplied, this dialog is suppressed; if yes, the file is just saved, and if no, an error is raised if the file exists. The filename extension determines the format of the resulting file: .scpt (or nothing) for a compiled script file, .scptd for a script bundle, .app for an application bundle.

Example

store script sayHello in file "myDisk:myFile" replacing yes

(On aliases and file specifiers and the differences between them, see Chapter 13. The verb run script, instead of a file, can take a string, and it then functions as a kind of second level of evaluation; see Chapter 12.)

When you save a script object with store script, the lines delimiting the definition block (if any) are stripped, which makes sense. So, for example:

script sayHello
        display dialog "Hello"
end script
store script sayHello in file "myDisk:myFile" replacing yes

What is saved in myFile is the single line:

display dialog "Hello"

A compiled script file to be loaded with load script or run with run script could originate from a store script command, or it could ...

Get AppleScript: The Definitive Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.