On Jan 23, 2017, at 23:34, Takaaki Naganoya <
email@hidden> wrote:
How about this?
That works, but I don't want to close any documents that are already open on the off-chance that something auto-opens after a crash, etc.
What I've settled on is this:
tell application id "com.apple.scripteditor2"
if not running then
launch
make new document
end if
activate
end tell
However I've noticed something quite odd.
I'm replacing a simple Activate a Specific Application action in Keyboard Maestro.
Keyboard Maestro runs AppleScript with `osascript` (for reasons known only to Peter), and this means that running a compiled script or a text script should produce the same result - yes?
But if I run the script above as a text script in a Execute an AppleScript action the open dialog OPENS and the new document fails to open!
That doesn't happen when I run the compiled script direct from Script Debugger or from FastScripts...
Hmm...
So I tried running a compiled script from the Execute an AppleScript action, and it works as expected – no open-dialog.
Running this shell script from BBEdit or FastScripts also produces the misfire.
read -r -d '' myScript <<'EOF'
tell application id "com.apple.scripteditor2" -- Script Editor
if not running then
launch
make new document
end if
activate
end tell
EOF
osascript -e "$myScript"