applescript saved as application doesn't run; strange workaround

I created an AppleScript script that works perfectly, but when I Save As Application, I get the message that the application "can't be opened". Looking into the app, which is technically a folder, I noticed that foo.app/Contents/MacOS/applet only gave me read (r) access. I gave myself execute (x) access (using Terminal and the chmod Unix command), and now the app works. I shouldn't have to do that, right? What am I doing wrong?

MacBook Pro 17", macOS 10.13

Posted on Apr 22, 2019 10:01 AM

Reply

Similar questions

10 replies

Apr 22, 2019 2:33 PM in response to VikingOSX

Not doing anything tricky. Open Script Editor, enter in a simple 'display alert "hello!"', Save As Application, and double-click the new app. Get the "can't open" alert. Do the chmod trick, double-click the app, and "hello!".


I think something is wrong with my system. I suspect it started with Security Update 2019-002 Version 10.13.6, which matches the version of macOS (High Sierra). (My Early 2011 MBP won't take Mojave.) Since the update Safari won't open certain web pages that open fine with Firefox, Opera, and Chrome. It claims that the server dropped the connection. The same pages open fine for others running Safari under High Sierra. Both problems could be seen as related to security, hence my suspicion regarding the security update. The update seemed to go smoothly.

Apr 22, 2019 1:39 PM in response to Ken Nellis

I can read. One does not normally dive into an AppleScript application bundle to run the executable. Either of the following will run the AppleScript application (in the following case, an AppleScript/Objective-C application) in the Terminal. It would do so if the application were pure AppleScript too:


open ~/Desktop/rtn_email.app


osascript ~/Desktop/rtn_email.app

Apr 24, 2019 10:11 AM in response to Ken Nellis

Apple's hearts may not be into Applescript any more ... SAD. Fired Sal, Applescript Evangelist.


May want to write an applescript to set the bit. Let's you drop something on app's icon and proceed from there.


 (* 
  Demonstration of how dropping files on AppleScript icon works.  Shows how to debug via on run path. Shows items added to folder.
  
 Save as an Application Bundle.  Don't check anything.
 
 Shows log statement.
 
 It is easier to diagnose problems with debug information. I suggest adding log statements to your script to see what is going on.  Here is an example.
	
For testing, run in the Script Editor.
	1) Click on the Event Log tab to see the output from the log statement
	2) Click on Run


Author: rccharles

 *)


-- Gets invoked here when you run in AppleScript editor.

on run
	--  debug lines
	set desktopPath to (path to desktop) as string
	
	-- here is a log statment.
	log "desktopPath = " & desktopPath
	
	-- Be sure to select a file on your DESKTOP.
	set see to alias (desktopPath & "Picture 1.png")
	
	-- Simulate dropped items list.
	set dropped_items to {see}
	
	common(dropped_items)
	
end run


-- Folder actions.
-- Gets invoked here when something is dropped on the folder that this script is monitoring.
-- Right click on the folder to be monitored. services > Folder Action Settup...

on adding folder items to this_folder after receiving added_items
	
	common(added_items)
	
end adding folder items to



-- Gets invoked here when something is dropped on this AppleScript icon

on open dropped_items
	
	common(dropped_items)
	
end open



on common(dropped_items)
	
	-- Write a message into the event log.
	log "  --- Starting on " & ((current date) as string) & " --- "
	tell application "Script Editor"
		activate
	end tell
	
	
	log "class = " & class of dropped_items
	
	
	repeat with droppedItem in dropped_items
		log "The droppedItem is " & droppedItem & "; class = " & class of droppedItem
		
		display dialog "The droppedItem is " & droppedItem giving up after 3
	end repeat
	
	
end common




Apr 24, 2019 9:09 AM in response to VikingOSX

Thank you for the suggestion. It still didn't work. I booted into Safe mode, recreated the script, ran it in Script Editor, and it worked. Then saved it as an application, double-clicked the new app, and got the same "The application xxx can't be opened." Rebooted into normal mode, reran the app, and same error. Then re-saved as an application to a new name and ran that, and still can't be opened. Did my "find foo.app -name applet -exec chmod +x {} \:" trick, and it ran perfectly.

Apr 22, 2019 1:15 PM in response to Ken Nellis

Ken,


When you save an AppleScript from Script Editor, whether script, script bundle, or application, it should already have the execute bit on in the default permissions when it is saved. You should then be able to double-click on that application and it will just run. I have never, in several years, had to venture into the application bundle and mark anything executable.


How are you attempting to run the saved application when it indicates that it cannot be opened?

Apr 22, 2019 3:23 PM in response to Ken Nellis

I am running macOS High Sierra 10.13.6 (17G6030) with the Security Update 2019-002 applied. Did not prevent me from saving a display alert "hello!" AppleScript from Script Editor as an application, and double-clicking it to run in Finder. Works fine here.


I suggest that you reboot into Safe Boot mode (press and hold the shift key until the progress bar appears). Safe boot is much slower than regular boot, so be patient. Try creating the script again, and saving as an application. Even if that does not work, reboot normally, and repeat the application creation to see if it works normally after Safe Boot.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

applescript saved as application doesn't run; strange workaround

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.