Re: If Statement Not Working
Re: If Statement Not Working
- Subject: Re: If Statement Not Working
- From: Nigel Garvey <email@hidden>
- Date: Mon, 30 Jul 2001 10:45:16 +0100
George Priggen wrote on Sun, 29 Jul 2001 15:20:31 -0700:
>
Anyone -
>
>
I have the following Applescript which does not perform the file switch when
>
employing the "If" statement.
>
>
tell application "Finder"
>
select {folder "PPBusiness" of folder "PP" of startup disk}
>
if {file "BCData.FP5" of folder "PPBusiness" of folder "PP" of startup
>
disk is in folder "PPBusiness" of folder "PP" of startup disk, file
>
"BCEmployee.FP5" of folder "PPBusiness" of folder "PP" of startup disk is in
>
folder "PPBusiness" of folder "PP" of startup disk} = true then
>
select {file "BCData.FP5" of folder "PPBusiness" of folder "PP" of
>
startup disk, file "BCEmployee.FP5" of folder "PPBusiness" of folder "PP" of
>
startup disk}
>
move selection to folder "NewPPEmail" of folder "Email Campaign" of
>
folder "PP" of startup disk
>
end if
>
end tell
>
>
What do I need to do to get the "If" statement to work in connection with
>
the second select section?
Besides Matt's insights, you could use 'try' instead. This would simply
fail and do nothing if the files didn't exist.
tell application "Finder"
try
tell folder "PPBusiness" of folder "PP" of startup disk
{file "BCData.FP5", file "BCEmployee.FP5"}
end tell
move the result to folder "NewPPEmail" of folder "Email Campaign"
of folder "PP" of startup disk
on error
end try
end tell
You'd probably want to set up something in the 'on error' section to
double-check the reason for the error.
George replied to Matt's suggestion:
>
But if I try to connect to two if statements with an "and":
>
>
tell application "Finder"
>
if file "BCData.FP5" of folder "PPBusiness" of folder "PP" of startup
>
disk exists and file "BCEmployee.FP5" of folder "PPBusiness" of folder "PP"
>
of startup disk exists then
>
move ... etc
>
>
Applescript will not allow me to do it. Is there a way of combining to two
>
if statements?
You just need to bracket the two Finder commands to make things clearer
to the compiler:
tell application "Finder"
if (file "BCData.FP5" of folder "PPBusiness" of folder "PP" of
startup disk exists) and (file "BCEmployee.FP5" of folder "PPBusiness" of
folder "PP" of startup disk exists) then
move ... etc
Timothy Bates suggested:
>
set fileA to "" & (name of startup disk) & "PP:PPBusiness:BCData.FP5"
>
set fileB to "" & (name of startup disk) & "PP:PPBusiness: BCEmployee.FP5"
>
--the initial "" makes sure the whole thing comes back as a string
>
--alternatively
>
set fileA to (name of startup disk & "PP:PPBusiness:BCData.FP5") as string
>
>
tell app "Finder
>
if (fileA exists and fileB exists) then
This of course requires Jon's Commands for the coercion; otherwise it's:
tell app "Finder"
if (file fileA exists and file fileB exists) then
... etc.
NG