Can no longer launch applets in 10.12.2

I have some scripts saved as apps that no longer launch from Finder or the OS script menu. Finder says:

The application “” can’t be opened.

Script menu says:

An error occurred. OSErr -10810.

They all worked before. Not sure what changed. I tried saving them in both SD and SE. Same results. Some of the applets even have the “can’t launch” thing over the icon (circle with diagonal line). The scripts work fine when run from within SD. Some scripts use AppleScriptObjC. Some use straight AppleScript.

Someone on the applescript-users list suggested killing and reseeding LaunchServices. Tried that - didn’t help.

Found the problem. I’ll just paste in my Apple bug report. Not sure if SD can fix this or if it’s being caused by some stupid bug/change in 10.12.2.

At some point, something has broken in 10.12.x. AppleScript apps saved in places such as ~/Library/Scripts/Applications/Safari/ no longer launch, but fail with cryptic error messages. If launched from Finder:

The application “___test” can’t be opened.

If launched from the OS scripts menu:

An error occurred. OSErr -10810

After a day’s worth of debugging and searching for answers, I finally figured out that the problem is caused by Script Editor or Script Debugger not setting the executable bits on the actual executable (blah.app/Contents/MacOS/applet) when the script is saved in locations other than /Applications.

This was previously not the case. As it is now, the user is no longer able to run scripts saved in this manner, which severely limits productivity.

Steps to Reproduce:

  1. From Script Editor or Script Debugger, make a new script.
  2. The script can be anything, such as “beep”.
  3. Save the script as an application in a folder other than /Applications. A good place is your ~/Library/Scripts folder so you can launch it from the OS scripts menu.
  4. Launch the app, either by double-clicking in Finder or choosing it from the OS scripts menu.

Expected Results:
It should launch.

Actual Results:
It does not launch and gives you a cryptic error that doesn’t help.

Version:
10.12.2 (16C67)

Apple bug is radar://29953249

Can you use the terminal to set the execute bit manually, at least as a temporary workaround? (I don’t have 10.2.2 available to test it.)

Yes, that’s what I’m having to do every time I edit and save a script. I threw the command into a do shell script, saved that as an applet into /Applications, and added it to the Dock, so at least it’s a minimal amount of intrusiveness.

Oh, more security bugs: My applet can no longer download the content of a url (using AppleScriptObjC). Sandboxing crap now gets overexcited and blocks this action from my unsigned app, even with the “Run apps from” set to “Anywhere”. So after a day of debugging the first problem, I’m hit right away with another serious roadblock.

Are you being blocked by App Transport Security layer?

You can add the exceptios to your info plist if so.

See https://cocoacasts.com/how-to-add-app-transport-security-exception-domains/

Remember this?
http://latenightsw.com/falsesense-of-security/

Jeez, how quickly I forget stuff like this. Thanks for reminding me. In my defense, it had been working before, then at some point stopped, which left me thinking it was a security update that screwed things up worse. Still not sure what changed that made it suddenly stop working.

Still waiting for a way to add arbitrary entries to the plist in SD. In the meantime, I’ll use a com.apple bundle ID.

Here’s a script I use – put it in SD’s Scripts menu:

use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "Foundation"
use scripting additions

-- check document is an applet
tell application id "com.latenightsw.ScriptDebugger6" -- Script Debugger.app
	tell document 1
		set theFile to file spec
		if theFile is missing value then
			beep
			display alert "Unsaved script" message "This script works only on documents that have been saved as applets." as critical buttons {"Cancel"} default button "Cancel"
			error number -128
		end if
		if script type is not script application then
			beep
			display alert "Document is not an applet" message "This script works only on documents that have been saved as applets." as critical buttons {"Cancel"} default button "Cancel"
			error number -128
		end if
	end tell
end tell
-- read the document's Info.plist file and get the existing value
set thePath to current application's NSString's stringWithString:(POSIX path of theFile)
set thePath to thePath's stringByAppendingPathComponent:"Contents/Info.plist"
set {theData, theError} to current application's NSData's dataWithContentsOfFile:thePath options:0 |error|:(reference)
if theData is missing value then error theError's localizedDescription() as text
set {thePL, theError} to current application's NSPropertyListSerialization's propertyListWithData:theData options:(current application's NSPropertyListMutableContainersAndLeaves) |format|:(missing value) |error|:(reference)
if thePL is missing value then error theError's localizedDescription() as text
-- find out what the user wishes to do
set existingValue to thePL's objectForKey:"NSAppTransportSecurity"
if existingValue is not missing value then
	set theResult to display alert "App Transport Security configuration" message "Click continue to reinstate the default security restrictions that stop this applet from connecting to insecure Web hosts." as critical buttons {"Cancel", "Continue"}
else
	set theResult to display alert "App Transport Security configuration" message "Click continue to remove the default security restrictions that stop this applet from connecting to insecure Web hosts." as critical buttons {"Cancel", "Continue"} default button "Cancel"
end if
if button returned of theResult is "Cancel" then
	beep
	error number -128
end if
-- change and save
if existingValue is missing value then
	thePL's setObject:{NSAllowsArbitraryLoads:true} forKey:"NSAppTransportSecurity"
else
	thePL's removeObjectForKey:"NSAppTransportSecurity"
end if
set {theData, theError} to current application's NSPropertyListSerialization's dataWithPropertyList:thePL |format|:(current application's NSPropertyListBinaryFormat_v1_0) options:0 |error|:(reference)
if theData is missing value then error theError's localizedDescription() as text
theData's writeToFile:thePath atomically:true
-- dirty the document
tell application id "com.latenightsw.ScriptDebugger6" -- Script Debugger.app
	tell document 1
		if compiled then
			set selection to {1, 0}
			set selection to space
			set selection to ""
		end if
	end tell
end tell

Why do you dirty the doc at the end? Won’t that cause the user to save again when the notice that or close the script, thereby obliterating the Info.plist? Also, that moves the selection. Just curious why that doesn’t bug you. :slight_smile:

Easy enough to fix:

tell application id "com.latenightsw.ScriptDebugger6" -- Script Debugger.app
   tell document 2
      if compiled then
         set {SelStart, selEnd} to character range of the selection
         set SelStart to SelStart + 1
         set selection to {1, 0}
         set selection to space
         set selection to {SelStart, selEnd}
      end if
      compile
   end tell
end tell

Quite the opposite. Changes to Info.plist don’t dirty a document, but they do persist between saves.

But why does it need to dirty it?

Because changes to the bundle don’t by themselves. Running this script is effectively changing the document behind SD’s back.

Yeah, I get what you’re saying. If it were me, I would know that I just ran the script that modifies the saved script which is already in disk, so there’s no reason to force SD to think it needs to save it again.

not good. I just ran into this problem. two applets that won’t launch, with the same “can’t be opened” error message.

worse for me. my Applications folder is protected; i.e., I maintain a separate Admin account for security.

fortunately, Transmit allows me to set the Execute bit locally. I’ll see if I can script that action :wink:

has anyone written a droplet to do this using terminal commands?

cheers,
Gregory