Applescript can't see a file I know exists

In this example code, I’m trying to do something with a file but Applescript refuses to acknowledge its existence…

set theFilename to POSIX file "/Users/iMacThere4iAm/Music/File.mov"
if exists file theFilename then
	display dialog theFilename & " exists!"
end if

I get an error at the ‘if exists…’ line:

This happens when I try to do anything with the file, I’m just checking if it exists as a simple example.

Anyone know why this happens? I must be doing something wrong, but I can’t see what!

Try this.

set theFilename to POSIX file "/Users/iMacThere4iAm/Music/File.mov" as alias

if exists theFilename then
	display dialog (theFilename as string) & " exists!"
end if

That doesn’t help, I’m afraid.

The error’s changed to:

And it still fails on ‘if exists…’

Hi,

to clarify: AppleScript works with HFS paths (colon separated) unlike shell scripts which expect POSIX paths (slash separated).
the error in your script occurs, when the file doesn’t exist, the coercion as alias causes the error
You can use this form

try
	set theFilename to alias "Leopard:Users:iMacThere4iAm:File.mov"
	display dialog theFilename as text & " exists!"
end try

or, machine independent

try
	set theFilename to alias ((path to home folder as text) & "File.mov")
	display dialog theFilename as text & " exists!"
end try

if you want to use the exist command, you need the help of the Finder or System Events


set theFilename to ((path to home folder as text) & "File.mov")
tell application "Finder"
	if exists file theFilename then
		display dialog theFilename & " exists!"
	end if
end tell

Good point Stefan

It has to exist to make it a alias.