Skip to content

Be aware of this Applescript-with-droplet bug

Another post thanks to Many Tricks' Peter Maurer; this particular bug bit me last night—I spent 30 minutes trying to figure out why a compiled AppleScript with a droplet wasn't working. I never did get it, so I emailed Peter, and he pointed me to these tweets from a while back…

And yea, that was the problem: As soon as I added the +x to the compiled script, everything worked as expected. The exact syntax is:

chmod +x /path/to/

I'm documenting this here so that I can find it more easily the next time I save a compiled droplet AppleScript and forget about this not-so-little bug.

5 thoughts on “Be aware of this Applescript-with-droplet bug”

  1. prehensileblog

    This confuses me. I hadn't noticed this issue and I'm running 10.12.4, so I opened the following in Script Editor, saved it as an application, and had no problems dropping a folder to make a disk image on the desktop. Is there a chance that security hacks i've implemented (system integrity and Gatekeeper) are preventing the issue you describe?

    property temppath : "/private/tmp/"
    property startnum : 0
    on open the_items
    	my build_archive(the_items)
    end open
    on build_archive(the_items)
    	repeat with the_item in the_items
    		set the_item to the_item as alias
    			tell application "Finder"
    				set sost to ((container of folder (the_item as string)) as alias) as string
    			end tell
    			set sost to POSIX path of sost
    		on error
    			set sost to "/Volumes/"
    		end try
    		set this_filepath to (the_item as string)
    		if last character of this_filepath is ":" then
    			tell me to set it_is_a_folder to true
    			set it_is_a_folder to false
    		end if
    		set thesourcename to (name of (info for the_item))
    		set the_source_file to POSIX path of this_filepath
    		set pos_filepath to sost
    		set thesourcename to replace_chars(thesourcename, "", "_")
    		set dest_file to (quoted form of (temppath & thesourcename & ".dmg"))
    			set my_command to "hdiutil create -srcfolder" & space & (quoted form of the_source_file) & space & "-format UDBZ" & space & dest_file
    			do shell script my_command
    			--display dialog my_command
    		on error onerr
    			display dialog onerr
    		end try
    		tell application "Finder"
    			set basename to thesourcename
    			if pos_filepath is "/Volumes/" then
    				set pos_filepath to (POSIX path of (path to desktop folder))
    			end if
    					set name_target to alias (POSIX file (pos_filepath & thesourcename & ".dmg"))
    					set startnum to startnum + 1
    					set thesourcename to text returned of (display dialog "A file with that name already exists. You may enter a new name or cancel" default answer (basename & startnum))
    				on error terrible_error
    					set startnum to 0
    					if terrible_error contains thesourcename then
    						tell me to do shell script "ditto -rsrcFork" & space & dest_file & space & "\"" & (pos_filepath & thesourcename & ".dmg") & "\""
    						exit repeat
    						exit repeat
    					end if
    				end try
    			end repeat
    		end tell
    			do shell script "rm" & space & dest_file
    		end try
    	end repeat
    end build_archive
    on replace_chars(this_text, _bad, _good)
    	set AppleScript's text item delimiters to the _bad
    	set the item_list to every text item of this_text
    	set AppleScript's text item delimiters to the _good as string
    	set this_text to the item_list as string
    	set AppleScript's text item delimiters to ""
    	return this_text
    end replace_chars
    on run
    	set the_items to ((choose folder) as list)
    end run
  2. prehensileblog

    Should've quoted the script somehow, apparently the blog messed it up. It may be easier for you to fix than for me.

  3. prehensileblog

    Seems that tabs were changed rather than omitted and quotes were smartened.

  4. prehensileblog

    Anyway, the point is that I have Script Editor 2.9, but I have no such problem. Any idea why?

    1. Sorry, haven't had time to try it yet - just reformatted it earlier. Will try to look at bit later tonight and see if it works for me.


Comments are closed.