Prevent "Choose file" from choosing packages?

I’ve written a few scripts that let a user choose a file and then convert it to another format. I perform various tests to see whether the chosen file is in a format that the script can convert. But I still can’t solve one problem:

“Choose file” lets a user select a file that’s really a package - for example the “About Downloads” file in the Downloads folder in Mountain Lion (and and perhaps other versions) is really a package containing folders with many PDF files. Is there a simple way to detect when a user has chosen a package so that I can display an error message?

I thought of testing for a colon as the last character of the path reported by System Events, but I wonder if there is a more direct method.

Thanks for any advice.


try this

set theFile to choose file
tell application "System Events" to set isFilePackage to package folder of theFile

Hi. Will this work?

tell application "Finder" to try
	(choose file)'s item 1 --on success, is package
end try

Edit: Stefan beat me to it, and his solution is better. :slight_smile:

Both excellent! Thank you for the quick and efficient suggestions.