This code:
use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions
tell application "Script Debugger"
set activeDoc to make new document with properties {name:"Test Save Script"}
set source text of activeDoc to "display dialog \"I ran!\""
set docName to the name of activeDoc
set savePath to ((POSIX path of (path to downloads folder)) as text) & "Test Save.app"
set exportFormat to enhanced application
save activeDoc in POSIX file savePath as exportFormat with run only
end tell
tell application "System Events"
tell application process "Script Debugger"
tell window docName
if exists sheet 1 then
tell sheet 1
repeat 200 times
set buttonProps to (properties of button "OK")
if enabled of buttonProps is true then
click button "OK"
exit repeat
else
delay 0.1
end if
end repeat
end tell
end if
end tell
end tell
end tell
tell application "Script Debugger" to close activeDoc saving no
Has the result of saving an app in the user’s downloads folder that, if run, displays a dialog “I Ran.”
This script, which is identical to the above script, except run inside a “run script:”
use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions
set scriptText to "use AppleScript version \"2.4\" -- Yosemite (10.10) or later
use scripting additions
tell application \"Script Debugger\"
set activeDoc to make new document with properties {name:\"Test Save Script\"}
set source text of activeDoc to \"display dialog \\\"I ran!\\\"\"
set docName to the name of activeDoc
set savePath to ((POSIX path of (path to downloads folder)) as text) & \"TestSave.app\"
set exportFormat to enhanced application
save activeDoc in POSIX file savePath as exportFormat with run only
end tell
tell application \"System Events\"
tell application process \"Script Debugger\"
tell window docName
if exists sheet 1 then
tell sheet 1
repeat 200 times
set buttonProps to (properties of button \"OK\")
if enabled of buttonProps is true then
click button \"OK\"
exit repeat
else
delay 0.1
end if
end repeat
end tell
end if
end tell
end tell
end tell
tell application \"Script Debugger\" to close activeDoc saving no"
run script scriptText
immediately returns the error:
I discovered this when trying to get Script Debugger to batch save scripts… trying to avoid the UI dialog sheet following the save, which I’m bypassing with UI scripting above. So I’d still be interested in bypassing that, if possible. There’s a thread on that at Late Night Software’s Script Debugger forum here: https://forum.latenightsw.com/t/cant-get-my-batch-deployment-script-to-work-with-code-signing-on/3678/2
I wasn’t aiming to cross-post that, but it’s turned into two questions:
- The very Script-Debugger-centric question “how can I avoid the dialog on save/export?”
- The question I assume doesn’t relate to script debugger in particular, "Under what circumstances does the same code behave differently when run as a “do script,” as opposed to being run directly?
I thought it was better to put question #2 here.