Saturday, December 16, 2017

#1 2009-11-11 01:54:57 pm

Whiterock
Member
Registered: 2009-09-09
Posts: 30

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.

Applescript:


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.


Filed under: file, choose, exists, NSOpenPanel

Offline

 

#2 2009-11-11 02:03:34 pm

StefanK
Member
From:: St. Gallen, Switzerland
Registered: 2006-10-21
Posts: 11482
Website

Re: Using 'exists' with 'choose file'

Hi,

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

Applescript:


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.

Applescript:


tell application "Finder" to set optsFound to exists options_file

Last edited by StefanK (2009-11-11 02:03:54 pm)


regards

Stefan


Filed under: Finder

Offline

 

#3 2009-11-11 04:53:49 pm

Whiterock
Member
Registered: 2009-09-09
Posts: 30

Re: Using 'exists' with 'choose file'

thanks.

so many things to forget about

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)