In an attempt to get better at Applescript I’ve downloaded Xcode and have been looking at sample scripts in Developer>Examples>Applescript Studio>
All of the sample scripts contain a reference to the variable ‘theObject’, and when I try to compile in Script Editor, in each case the variable gets flagged, and it won’t compile or run.
Is there a difference between compiling something in Script Editor and Xcode?
Below a script called ‘save panel’ :
(*Save Panel.applescript *)
(* This example demonstrates how to use the ‘save-panel’ class, either as a modal panel or as a panel attached to a window. The ‘save panel’ is a property of the application object. *)
(* ==== Event Handlers ==== *)
– This event handler is called when the “Display Save Panel” button is clicked, which when clicked the various parameter values pulled from the text fields to be sent to “display”.
on clicked theObject
– Get the values from the UI
tell window of theObject
set theTitle to contents of text field “title”
set thePrompt to contents of text field “prompt”
set theFileType to contents of text field “file type”
set theDirectory to contents of text field “directory”
set theFileName to contents of text field “file name”
set treatPackages to contents of button “treat packages” as boolean
set asSheet to contents of button “sheet” as boolean
-- Setup the properties in the 'save panel' tell save panel set title to theTitle set prompt to thePrompt set required file type to theFileType set treat packages as directories to treatPackages end tell -- Determine which way to display the panel if asSheet then -- Display the panel as sheet (in which case the result will happen in 'on panel ended'). -- One thing to note is that the script will not stop processing until the panel is presented but continues on. You must use the 'on panel ended' event handler to get notified when the panel has finished. -- The 'in directory' and 'with file name' parameters are optional. display save panel in directory theDirectory with file name theFileName attached to window of theObject else -- Display the panel. -- Unlike the 'attached to' variant, the script does stop processing until the panel is finished. -- The 'in directory' and 'with file name' parameters are optional set theResult to display save panel in directory theDirectory with file name theFileName if theResult is 1 then set contents of text field "path name" of window "main" to path name of save panel else set contents of text field "path name" of window "main" to "" end if end if
– This event handler is called when the panel presented with the ‘display attached to’ command is finished.
on panel ended theObject with result withResult
if withResult is 1 then
set contents of text field “path name” of window “main” to path name of save panel
set contents of text field “path name” of window “main” to “”
end panel ended