Re: rm does not always remove immediately
Re: rm does not always remove immediately
- Subject: Re: rm does not always remove immediately
- From: Peter Waibel <email@hidden>
- Date: Tue, 12 Dec 2006 16:49:44 +0100
Am 12.12.2006 um 14:52 schrieb Luther Fuller:
At one time, perhaps a year ago, use of 'do shell script "rm ..."'
would simply destroy an item immediately. A subsequent test in a
script would find the item gone.
Christopher Nebel's reply to Yvon Thoraval ("equivalence mv
file_or_folder ~/.Trash and tell app "Finder" to move
file_or_folder to trash") reminded me that this is no longer the
case and I'm curious why.
Some months ago, I found that after using 'do shell script
"rm ..."', the file was still there. I have had to discontinue use
of 'rm'. Rather that doing a lot of explaining, here's a test
application I just wrote ...
property testFolderName : "rm-test folder"
tell application "Finder"
if not (exists folder testFolderName of desktop) then
make new folder at desktop with properties {name:testFolderName}
set testFolder to the result as alias
else
set testFolder to (folder testFolderName of desktop) as alias
end if
--
make new folder at testFolder with properties {name:"x"}
set testItem to the result as alias
--
try
"rm -fr " & (quoted form of POSIX path of testItem)
do shell script the result
on error
display dialog "Error during rm"
return
end try
--
delay 3
if exists folder "x" of testFolder then
"It's still there!"
else
"It's gone!"
end if
display dialog the result
end tell
Hi Luther,
maybe "rm" is not doing wrong, but the finder may be a bit slow.
I think the finder does not notice the removal of a file immediatelly.
Below is your script with a modification.
Instead of asking the finder if a file exists
the modified script tries to create an alias from the path.
Peter
property testFolderName : "rm-test folder"
tell application "Finder"
if not (exists folder testFolderName of desktop) then
make new folder at desktop with properties {name:testFolderName}
set testFolder to the result as alias
else
set testFolder to (folder testFolderName of desktop) as alias
end if
--
make new folder at testFolder with properties {name:"x"}
set testItem to the result as alias
--
--return ((testFolder as string) & "x") as alias
try
"rm -fr " & (quoted form of POSIX path of testItem)
do shell script the result
on error
display dialog "Error during rm"
return
end try
--
(*
delay 3
if exists folder "x" of testFolder then
"It's still there!"
else
"It's gone!"
end if
display dialog the result
*)
end tell
--return ((testFolder as string) & "x") as alias
try
((testFolder as string) & "x") as alias
"It's still there!"
on error
"It's gone!"
end try
display dialog the result
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/mailman//archives/applescript-users
This email sent to email@hidden