File testing in applescript

I’m using this as a loose guide:

So, I use open-panel to have the user select either a directory or a file.

Then I want to test their choice, if file get path to parent directory.

Sooo, following the above linked example. I

on choose menu item theObject
	if the name of theObject = "openFile" then
		set can choose directories of open panel to true
		set can choose files of open panel to true
		display open panel in directory (system attribute "HOME")
		set inputFile to item 1 of (path names of open panel as list)
		set item_info to info for inputFile
		display dialog fileType
		set title of window "main" to "Input File: " & inputFile
		show window "main"
	end if
end choose menu item

I don’t even get to the next step as “set item_info to info for inputFile” prodcues an error:

Applescript Error
File /Users/username/chosendirectory wasn’t found (-43)

I’ve done tons of searches (google and otherwise) for “file type” “file test” “ste type” and searched apple docs for type, set. Can’t find any examples >.<

edit for clarification I don’t care what kind of file it is, only that it is not a directory.

The open panel returns a (list of) POSIX path(s). You need to coerce it to something you can use.

set inputFile to POSIX file (item 1 of (path names of open panel as list))

Thank you very much, Bruce. I’d just found my answer here on the forums in this thread: and had come to post it for others.

Your answer is much more to the point for my issue though. :slight_smile: