• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: rm does not always remove immediately
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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
References: 
 >Re: equivalence mv file_or_folder ~/.Trash and tell app "Finder" to move file_or_folder to trash (From: Christopher Nebel <email@hidden>)
 >rm does not always remove immediately (From: Luther Fuller <email@hidden>)

  • Prev by Date: rm does not always remove immediately
  • Next by Date: Re: rm does not always remove immediately
  • Previous by thread: rm does not always remove immediately
  • Next by thread: Re: rm does not always remove immediately
  • Index(es):
    • Date
    • Thread