Check if item dropped on to AS app is allowed?

I cobbled together a simple script that runs a shell script on folders with the .iconset name ending, and I’m wanting the script to display a dialog message if the item dropped on to the script saved as an application doesn’t meet the requirements.

Here’s the script

on open these_items
	
	tell application "Finder"
		set theSelection to selection
		set theFolder to (item 1 of theSelection) as text
	end tell
	
	do shell script "iconutil -c icns" & space & quoted form of POSIX path of theFolder
	
end open

Ideally it would check if the type of item droppped on to it is a folder, and also that the name ending is .iconset (e.g. “folder name.iconset”), but maybe it would be enough to check just the name ending?

Any help would be appreciated :slight_smile:

You have to use the list of aliases passed in the ‘open’ handler’s parameter variable, which is ‘these_items’ in your script. When an alias is coerced to text, the resulting path ends with a colon if it’s to a folder or a package/bundle.

on open these_items
	
	repeat with this_item in these_items
		set item_path to this_item as text
		if (item_path ends with ".iconset:") then
			do shell script ("iconutil -c icns" & space & quoted form of POSIX path of this_item)
		else
			display dialog ("\"" & item_path & "\" isn't an \".iconset\" folder.") buttons {"Skip"} default button 1 with icon caution
		end if
	end repeat
	
end open

This works great, thanks a lot! :smiley: