Why does AppleScript fail, but works as a shell script, Mojave Beta 5?

I had a macro with two scripts in a Keyboard Maestro group for BBEdit only.

The first was a shell script:

/usr/local/bin/growlnotify  \
	--appIcon "BBEdit" \
	--identifier "$RANDOM" \
	--message "Setting current file to 'Unix Shell Script'" \
	--title "Keyboard Maestro"

and the second was an AppleScript:

tell application "BBEdit"
	activate
	set source language of text document 1 to "Unix Shell Script"
end tell

It threw an error, every time:

I couldn't get the exact error message, even if I set the output type to “window”.

So I tried putting the AppleScript into the shell script block, so it now looks like this:

/usr/local/bin/growlnotify  \
	--appIcon "BBEdit" \
	--identifier "$RANDOM" \
	--message "Setting current file to 'Unix Shell Script'" \
	--title "Keyboard Maestro"

/usr/bin/osascript <<EOT
tell application "BBEdit"
	activate
	set source language of text document 1 to "Unix Shell Script"
end tell
EOT

I ran it again, and this time, it worked. No errors.

Why would that be?

/Applications/BBEdit.app:
CFBundleShortVersionString: 12.1.6
CFBundleVersion: 410103

/Applications/Keyboard Maestro.app:
CFBundleShortVersionString: 8.2.4
CFBundleVersion: 8.2.4

On Mac 10.14 (18A353d) aka “Mojave Public Beta ¿5? or whatever is current as of 2018-08-13”

Running Keyboard Maestro 8.2.3 on macOS 10.12.6

I tested this script in both Script Debugger and KM, and it worked fine with no errors.
So it must be a Mojave Beta issue.

Make sure you are using the latest ver of KM, and have reset the KM Accessibility permissions. Although this should be fixed, you may have to do one or more of the following until it works.

  1. Restart the KM Editor
  2. Restart the KM Engine
  3. Restart your Mac

Yeah, it works if I set it up as an AppleScript in BBEdit's menu too, but I get an error from Keyboard Maestro if I try to select that Script’s menu item.

This is so weird I'm assuming it has to be a Mojave-beta issue.

To execute the script from KM, you should use the Execute an AppleScript action.

The error is shown complete in the Engine.log file (Help ➤ Open Logs Folder).

Mojave Public Beta 5 / Developer Beta 6 has very broken AppleScript permissions as far as Keyboard Maestro is concerned. It toggles permission back and forth between Keyboard Maestro and Keyboard Maestro Engine. For some/most people, this results in it prompting for permissions twice for every time you try to do anything. For others it seems it just does not prompt at all and disallows it. It seems you fall in to this camp.

This is a regression in Public Beta 5 / Developer Beta 6 and I have heard no word from Apple as far as them working to resolve this. Hopefully they are.

Actually, that makes sense, given what I've seen elsewhere. I have AppleScript “apps” which now fail to run, and AppleScript scripts which say they have no permission to do something, but never prompt me to give that permission.

I certainly hope this will be fixed before Mojave hits 1.0. Otherwise, Mojave is going to be a huge step-back for automation on the Mac.

No apparent improvement in Developer Beta 7 (which will presumably drop as Public Beta 6 shortly).

A pity – I would have liked the dark screens of Mojave – but at this stage it feels more like gathering storm clouds for automation.