AppleScript application bundle accepts dropped items

Hi,

Does anyone know if it’s possible to make an app bundle accept dropped files and perhaps send them to a folder within the bundle? Or should I use a disk image.

Thanks,
kel

Hello kel1

The Finder refuses to do the job but the command mv accept to do it.
My understanding is that the Shell make no difference between a folder, a package, an application (which is a package).

#=====

on open sel # sel contient une liste d'alias des éléments 
	# qu'on a déposés sur l'icône du script (la sélection)
	
	set myPath to quoted form of POSIX path of (path to me) as text
	
	repeat with aFile in sel
		do shell script "mv " & quoted form of POSIX path of (aFile as text) & space & myPath
	end repeat
	
end open # fin 2

#=====

Of course, it may be better to store the files in a subfolder of the package but I’m sure that you can do that without me :wink:

Yvan KOENIG (VALLAURIS, France) dimanche 21 septembre 2014 12:16:58

Here is the “on open” section of one that I wrote the other day. It’s a “wrapper” for a new AU/X emulator called Shoebill, and it’s designed to let you drop a ROM file and a disk image file into it.

Some of this code is very messy, with commands that really aren’t needed at all, mostly because I haven’t cleaned up some older code that I reused. Also, that older code was written before I learned to use System Events instead of the Finder. Probably the Finder should be replaced with System Events to make it faster wherever possible.

property msgTitle : "AUXrunner"
property sizeList : {"262144"} -- known good ROM file sizes

on open theDrop
	if (count of theDrop) is greater than 1 then
		set dialogText to "Drop either a file named "MacII.rom" or a disk image  on me." & return & return & "Drop only one file at a time."
		errorQuit(dialogText)
	end if
	repeat with dropFile in theDrop
		tell application "System Events"
			 set dropName to the name of dropFile
			set dropExt to the name extension of dropFile
		end tell
		if dropName is "MacII.ROM" then
			set dropFile to dropFile as string
			tell application "Finder"
				set thisPosix to POSIX path of (dropFile as alias)
				set romSize to size of (dropFile as alias) as string
			end tell
			if romSize is in sizeList then
			else
				tell me to activate
				display dialog "The file that you dropped does not have the correct size for use in this system." buttons {"Sorry"} default button 1 with title msgTitle giving up after 20
				error number -128
			end if
			set thisApp to path to me as text
			set romFilePath to (thisApp & "Contents:Resources:Files:rom:Macii.rom")
			set romFilePosix to quoted form of (POSIX path of romFilePath)
			try
				do shell script "cp " & quoted form of thisPosix & space & romFilePosix
			on error
				set dialogText to "Could not copy ROM file into this application. Sorry."
				errorQuit(dialogText)
			end try
			tell me to activate
			display dialog "ROM file copied successfully." & return & return & "Add disk images according to the instructions." buttons {"OK"} with title msgTitle giving up after 10
			error number -128
		else
			set extList to {"cdr", "iso", "dmg", "dsk", "img", "toast", "image"}
			if dropExt is in extList then
				my installDisk(dropFile)
			else
				set dialogText to "Please drop either a file named "MacII.rom" or a disk image on me." & return & return & "Do not drop any other kind of file."
				errorQuit(dialogText)
			end if
			
		end if
	end repeat
	error number -128
end open

on run
-- omitted
end run

on installDisk(dropFile)
	tell application "Finder"
		set newDiskPosix to POSIX path of (dropFile as alias)
	end tell
	set thisApp to (path to me) as text
	set myContents to (thisApp & "Contents:") as text
	set myContentsPosix to POSIX path of myContents
	set resourcesFolder to (thisApp & "Contents:Resources:") as text
	set filesPosix to POSIX path of resourcesFolder & "Files/"
	set disk0Folder to filesPosix & "disk0/"
	set disk0Posix to do shell script "ls" & space & quoted form of disk0Folder
	if the disk0Posix is "" then
		tell me to activate
		display dialog "Do you want me to move" & return & return & newDiskPosix & return & return & "into this application as bootable disk0 in AU/X?" buttons {"Yes", "Cancel"} default button 1 with title msgTitle
		if button returned of result is "Cancel" then
			quit
			error number -128
		else
			do shell script "mv -f" & space & quoted form of newDiskPosix & space & quoted form of disk0Folder
			tell me to activate
			display dialog "Your disk image has been moved into this application." & return & return & "Please restart me." buttons {"OK"} with title msgTitle giving up after 5
			error number -128
		end if
	else
		set oldDisk0Path to (disk0Folder & disk0Posix)
		tell me to activate
		display dialog "Do you want me to move" & return & return & newDiskPosix & return & return & "into this application as bootable disk0 in AU/X, replacing the existing disk: " & return & return & disk0Posix buttons {"Yes", "Cancel"} default button 1 with title msgTitle
		if button returned of result is "Cancel" then
			quit
			error number -128
		else
			display dialog "Do you want to move the existing disk to the Trash (so you can recover it) or delete it permanently?" buttons {"Move to Trash", "Delete forever"} default button 1 with title msgTitle
			if button returned of result is "Delete forever" then
				do shell script "rm" & space & quoted form of oldDisk0Path
				do shell script "mv -f" & space & quoted form of newDiskPosix & space & quoted form of disk0Folder
				activate
				display dialog "Your disk image has been moved into this application." & return & return & "Please restart me." buttons {"OK"} with title msgTitle giving up after 5
				error number -128
			else
				tell application "Finder"
					set oldImage to POSIX file oldDisk0Path as alias
					move file oldImage to trash
				end tell
				do shell script "mv -f" & space & quoted form of newDiskPosix & space & quoted form of disk0Folder
				activate
				display dialog "Your disk image has been moved into this application." & return & return & "Please restart me." buttons {"OK"} with title msgTitle giving up after 5
				error number -128
			end if
		end if
	end if
	
	tell me to quit
	error number -128
end installDisk

on errorQuit(dialogText) -- Fatal error, quitting script
	tell me to activate
	display dialog dialogText buttons {"OK"} default button 1 with icon stop with title msgTitle giving up after 20
	tell me to quit
	error number -128
end errorQuit

Someone who actually knows something about Applescript can do a lot better than this. I simply throw code into the editor at random until something works.

Hi Yvan and emendelson,

I can’t use droplets because droplets do not accept all files.

As I was driving along, it came to mind that a installer package might work. I remember using something called Package Maker and was sure that Apple had included it in Xcode’s Developer Tools. Well, it seems that it needs to be downloaded, but the one I found doesn’t work here in Mavericks. That’s strange, because I was sure Apple would have included a installer package.

Thanks anyway though,
kel

Interesting: which files are not accepted?

And, although I haven’t tested it, this might be of interest to readers of this thread:

https://github.com/RichardBronosky/AppleScript-droplet

kel1 is probably speaking of :
internet location file

He opened a thread :
http://macscripter.net/viewtopic.php?id=43021
dedicated to them.

Yvan KOENIG (VALLAURIS, France) lundi 22 septembre 2014 18:50:57