Re: Exists statements
Re: Exists statements
- Subject: Re: Exists statements
- From: Paul Berkowitz <email@hidden>
- Date: Tue, 22 Oct 2002 11:03:33 -0700
On 10/22/02 7:54 AM, "email@hidden" <email@hidden>
wrote:
>
I'm writing a script that needs to determine if a certain file exists or
>
not. I need to have it perform an action only if the file does not exist.
>
This is where I'm running into problems. The code I have so far is:
>
>
tell application "Finder"
>
if {file "dpath" of folder "preferences" of folder "system folder" of
>
startup disk exists} is "false" then choose folder with prompt "Locate data
>
Folder"
You seem to have immigrated from another scripting language. You can't make
assumptions about how symbols such as {} and "" are going to behave in a new
language.
{anything} represents a list or a record in AppleScript nothing else.
Without labels:values with colons, it's a list. Without a comma, its a
single item list. "anything" is always a string. So here you're asking if a
particular single item list
{file "dpath" of folder "preferences" of folder "system folder" of
startup disk exists}
namely a single-item list whose contents are the result of of an 'exists'
statement, thus a boolean value either true or false
{true} -- a list
or
{false} -- a list
is equal to the string (text)
"false"
Well of course it isn't. Even though an equality statement can coerce the
data type on the right to that on the left
{false}
still does not equal
{"false"}
Use parentheses, not list brackets, to contain an expression, and use
boolean true and false, not strings, for true and false.
tell application "Finder"
if (file "dpath" of folder "preferences" of folder "system folder" of
startup disk exists) is false then choose folder with prompt "Locate data
Folder"
end tell
More neatly, use Ed Walter's version (pre-OS X only)
tell application "Finder"
if not (exists file "dpath" of preferences folder) then
set dataFolder to choose folder with prompt "Locate data
Folder"
else
set dataFolder to path to preferences folder
end if
end tell
It has to be done differently, using the Standard Addition 'path to
preferences' in OS X.
It's time for you to read up on the AppleScript language in the AppleScript
Language Guide.
--
Paul Berkowitz
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.