Droplet works by itself but not from Xcode

this droplet works without xcode but doesnt work inside it…


on open listOfDocs
	set numDocs to count of listOfDocs
	set currentDoc to 1
	repeat with theDoc in listOfDocs
		set fileInfo to name extension of (info for theDoc)
		display dialog "File " & currentDoc & " of " & numDocs & " is a  " & fileInfo & ": " & name of (info for theDoc) buttons {"Print", "Stop Printing", "Skip This One"} default button 1 giving up after 3
		try
			if fileInfo = "doc" then
				tell application "Microsoft Word"
					activate
					open theDoc as alias
					print theDoc as alias
					quit
				end tell
				delay (0.4 * minutes)
			else if fileInfo = "sql" then
				tell application "TextEdit"
					activate
					open theDoc as alias
					print theDoc as alias
					quit
				end tell
				delay (0.4 * minutes)
			end if
		on error
			display dialog �
				"either that item wasnt printable, you are not conected to the printer, you dumb or i hate you... so fix one of those things!" buttons {"I will try to be smarter next time"} default button 1 with icon 2
		end try
		set currentDoc to (currentDoc + 1)
	end repeat
end open

By “doesn’t work” you mean crashes at the last second?

Try adding “return true” between the “end repeat” and “end open” lines. This is a bug in AppleScript Studio that should be fixed eventually.

Hope this helps…

it says that the variable ListOfDocs isnt defined

ListofDocs or listofDocs? (Case matters). Just wanted to check on that, I’ll also take a more in depth look too…

I just tried it in Xcode and didn’t have a problem. Double-check all your variable names again. Not sure what else to suggest…

Also, try using the Clean button to clean your current target, and then the build button to rebuild it from scratch.

Hope this helps…

i checked on action drop
and it does nothing absolutly nothing…
and this doesnt work

on drop theObject drag info listOfDocs
	set numDocs to count of listOfDocs
	set currentDoc to 1
	repeat with theDoc in listOfDocs
		set fileInfo to name extension of (info for theDoc)
		display dialog "File " & currentDoc & " of " & numDocs & " is a  " & fileInfo & ": " & name of (info for theDoc) buttons {"Print", "Stop Printing", "Skip This One"} default button 1 giving up after 3
		try
			if fileInfo = "doc" then
				tell application "Microsoft Word"
					activate
					open theDoc as alias
					print theDoc as alias
					quit
				end tell
				delay (0.4 * minutes)
			else if fileInfo = "sql" then
				tell application "TextEdit"
					activate
					open theDoc as alias
					print theDoc as alias
					quit
				end tell
				delay (0.4 * minutes)
			end if
		on error
			display dialog ¬
				"either that item wasnt printable, you are not conected to the printer, you dumb or i hate you... so fix one of those things!" buttons {"I will try to be smarter next time"} default button 1 with icon 2
		end try
		set currentDoc to (currentDoc + 1)
	end repeat
end drop

or this

on drop theObject drag info listOfDocs
	set numDocs to count of listOfDocs
	set currentDoc to 1
	repeat with theDoc in listOfDocs
		set fileInfo to name extension of (info for theDoc)
		display dialog "File " & currentDoc & " of " & numDocs & " is a  " & fileInfo & ": " & name of (info for theDoc) buttons {"Print", "Stop Printing", "Skip This One"} default button 1 giving up after 3
		try
			if fileInfo = "doc" then
				tell application "Microsoft Word"
					activate
					open theDoc as alias
					print theDoc as alias
					quit
				end tell
				delay (0.4 * minutes)
			else if fileInfo = "sql" then
				tell application "TextEdit"
					activate
					open theDoc as alias
					print theDoc as alias
					quit
				end tell
				delay (0.4 * minutes)
			end if
		on error
			display dialog ¬
				"either that item wasnt printable, you are not conected to the printer, you dumb or i hate you... so fix one of those things!" buttons {"I will try to be smarter next time"} default button 1 with icon 2
		end try
		set currentDoc to (currentDoc + 1)
	end repeat
end drop

Hang on, you’re almost there! :smiley:

Actually, you had the right script to begin with, using the “on open” handler just like regular AppleScript does. Generally, for a droplet, you can just use the same code in your AppleScript Studio droplet that you used in your regular AppleScript droplet. The one exception to this, as I mentioned before, is to add the “return true” line right at the end of it, to workaround that bug in ASS’s “on open” handler.

But before you get to the AppleScript itself, first you need to open the “MainMenu.nib” file in Interface Builder and connect an “open” event handler to the “File’s Owner” instance in the .nib file. Use this image as a guide. Select the “File’s Owner” (which represents your application itself, in a sense) then click the “open” event handler under the Application section, then choose the AppleScript that will handle that event (it should show your default applescript in the bottom section of the Inspector window in IB). Click “Edit Script” and paste the following script into it:

on open listOfDocs
	set numDocs to count of listOfDocs
	set currentDoc to 1
	repeat with theDoc in listOfDocs
		set fileInfo to name extension of (info for theDoc)
		display dialog "File " & currentDoc & " of " & numDocs & " is a? " & fileInfo & ": " & name of (info for theDoc) buttons {"Print", "Stop Printing", "Skip This One"} default button 1 giving up after 3
		try
			if fileInfo = "doc" then
				tell application "Microsoft Word"
					activate
					open theDoc as alias
					print theDoc as alias
					quit
				end tell
				delay (0.4 * minutes)
			else if fileInfo = "sql" then
				tell application "TextEdit"
					activate
					open theDoc as alias
					print theDoc as alias
					quit
				end tell
				delay (0.4 * minutes)
			end if
		on error
			display dialog "either that item wasnt printable, you are not conected to the printer, you dumb or i hate you... so fix one of those things!" buttons {"I will try to be smarter next time"} default button 1 with icon 2
		end try
		set currentDoc to (currentDoc + 1)
	end repeat
	return true -- <--- this is a key step to prevent the crash of your droplet at the very end
end open

Again, this script is basically your original plus the “return true” line.

Then, you’re all set.

Hope this helps…

P.S.
Oh, the “on drop” handler is meant for when you drop files onto an object in a window of the application or something, rather than on the icon of the application itself (at least I think that’s how it works, I haven’t quite got to that yet)…

sigh…
applescript error -1708
why does it hate me!?!?!?!?!?!?!?