Re: applescript-users digest, Vol 3 #2495 - 18 msgs
Re: applescript-users digest, Vol 3 #2495 - 18 msgs
- Subject: Re: applescript-users digest, Vol 3 #2495 - 18 msgs
- From: Robert Poland <email@hidden>
- Date: Fri, 5 Mar 2004 12:40:36 -0700
On Mar 5, 2004, at 2:53 AM, Bernard Azancot wrote:
Le 5 mars 04, ` 03:57, email@hidden a icrit :
Just a newbie surprise.
I have tried an elementary script to delete temp files.
It goes like this:
---
tell application "Finder"
try
delete file "tempA" of desktop
delete file "tempB" of desktop
delete file "tempC" of desktop
end try
end tell
---
-->
tempA is deleted
tempB & tempC are not
--__--__--
Message: 2
Date: Thu, 4 Mar 2004 13:34:04 -0700
From: Doug McNutt <email@hidden>
No answer but I'd add an "on error" to the try loop or remove the
"try" altogether. I'll bet Finder thinks it has some error that
you're not seeing.
Bingo !
If I remove the "try", it works fine.
2 subsidiary questions:
- 1 Why is this "try" a problem ?
- 2 If I remove the "try", I am going to get an error message when
one of the 3 temp files is not found. How can I avoid it ? "On
error " ? If yes, would be the syntax ?
1)
For some reason you are probably getting an error after the first
file is moved to the Trash. When you get an error the "try"
statement goes directly to its "on error" clause if there is one, if
not then it just goes directly to the "end try". You can see the
error if you do something like this:
----------
tell application "Finder"
try
delete file "A" of desktop
delete file "B" of desktop
delete file "C" of desktop
on error error_message number error_number
display dialog error_message buttons {"OK"} default button 1
end try
end tell
----------
2)
There are two ways of taking care of the possibility of a missing
file. One is to put each delete statement in its own try block:
----------
tell application "Finder"
try
delete file "A" of desktop
on error error_message number error_number
display dialog error_message buttons {"OK"} default button 1
end try
try
delete file "B" of desktop
on error error_message number error_number
display dialog error_message buttons {"OK"} default button 1
end try
try
delete file "C" of desktop
on error error_message number error_number
display dialog error_message buttons {"OK"} default button 1
end try
end tell
----------
The other is to test to see if the file is there before deleting it:
----------
tell application "Finder"
try
if exists file "A" of desktop then delete file "A" of desktop
if exists file "B" of desktop then delete file "B" of desktop
if exists file "C" of desktop then delete file "C" of desktop
on error error_message number error_number
display dialog error_message buttons {"OK"} default button 1
end try
end tell
----------
- Ken
I wonder how this would work
tell application "Finder"
try
delete file "tempA" of desktop
delay 1
delete file "tempB" of desktop
delay 1
delete file "tempC" of desktop
end try
end tell
--
Bob Poland - Englewood, CO
http://www.ibrb.org/
_______________________________________________
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.