Using 'exists' with 'choose file'

I’ve found that an Applescript app I use often will not compile anymore under the latest XCode and Snow Leopard. Attempting to adapt it to the new conditions has been slow and annoying. Methods that worked perfectly previously will no longer work.


set options_file to choose file with prompt "Pick the file containing the extra options:"
if (exists options_file) then
    set optsFound to true
end if

gives error -1708.
I’ve looked at NSOpenPanel but this is beyond me. I tried ‘exists’ with valid aliases and got the same error. How do I fix this? Maybe I don’t have to check the validity of the file path here but it is necessary elsewhere.

Hi,

logically the file exists when the user selects one.
You could catch the error in case of the user presses “Cancel”


try
	set options_file to choose file with prompt "Pick the file containing the extra options:"
	set optsFound to true
on error
	set optsFound to false
end try

BTW: to check the existence of a file with the keyword exists, you need the Finder or System Events e.g.


tell application "Finder" to set optsFound to exists options_file

thanks.

so many things to forget about