Finder MOVE to server doesn't erase original file?

I have moved files from the desktop to folders using the following code:

tell application "Finder"
	set outFolder to folder "MyFinalFolder"
	move file ("MyFileOnDT.txt") to outFolder as alias
	end tell

I figured that to move a file from the desktop to the root level of a mounted server, the code would be this:

tell application "Finder"
	move file ("MyFileOnDT.txt") to "ServerVolume"
end tell

What happens is, it does copy the file to the server, but it does not delete the file on the desktop as it should if you use “move”.

Any idea what I am doing wrong??

Model: G5 Tower (not Intel) - Script Editor ver 2.1.1
AppleScript: Tiger
Operating System: Mac OS X (10.4)

  1. Don’t use the Finder for this.

  2. Copy the file to the server with your preferred command-line tool via “do shell script”, check for success, and upon success delete the original with another shell operation.

And, you’re not doing anything wrong. The Finder always leaves the original when you move a file from one volume to another (or drag it between Finder windows). Finder’s Help says: You can move files or folders by dragging the icons to a new folder. If you drag the files or folders to a different disk, or if you drag them from a locked folder or disk, they will be copied, not moved. But also: To move files to a different disk, hold down the Command key while you drag the icons. Can’t do that in AppleScript, so use a shell script (mv source target) or delete after the move.

I’m trying to do exactly this, but how does one check for success? I know that there is an “exists” property I can check with applescript, but will that account for partial files that are still in transit?

Thanks very much.

EDIT: I thought I’d go ahead and add details since you guys usually come up with a much better all around method than I do. I’m basically just trying to move every file in a particular folder to a mounted share. What I’m struggling with is making sure this is done safely as the files are rather irreplaceable. These are rather large files that could take quite some time to transfer. I don’t want the originals to be deleted until the files are definitely on the server and complete. I’m especially concerned with what might happen if the network dies in the middle of a transfer.

Just thought I’d share. Thanks.

Check out ‘md5sum’

It will checksum the files for you. To test if they are complete and undamaged, checksum the originals, copy to the server and then checksum the copies. If the checksum matches, the files are complete and identical to the originals.

I am sure someone out there already has a script to do this.

Andy

Browser: Safari 412
Operating System: Mac OS X (10.4)

Bless you tugboat666, that that got me on the right track. I used md5 instead of md5sum since it seems to be less wordy. I thought I’d post what I came up with just in case A.) I’m doing anything stupid and b.) anyone else might find it useful.

Just to be sure, when the script times out, it will skip the delete command, right? I know I’m probably not doing this is in the most straightforward way, but it’s the best I could come up with.

localFilePath and remoteFilePath are defined earlier in the script and are set to the locations of the original file and the copied file respectively. infile is a alias to the original file (it’s not in POSIX form and I had trouble with delete and Unix style paths earlier).



set localFileSum to (do shell script "md5 -q " & localFilePath)
	
set remoteFileSum to (do shell script "md5 -q " & remoteFilePath)
	
with timeout of (120 * 60) seconds
		
		repeat until localFileSum is equal to remoteFileSum
			
		end repeat
		
		delete infile
		
end timeout


Suggestions welcomed.

You’ll have to

tell application "Finder" to delete infile

which will put it in the trash.

To do it from the shell, you would use:

do shell script "rm " & quoted form of POSIX path of infile

which is irrevocable - the file does not go to the Finder’s trash, it just goes!

I assume there’s something in the repeat loop in your actual script, because if the two aren’t equal, you’ll never get out of it. Was your intent to wait for something? If the sums don’t test equal are you going to delete the one on the server and move the one from your Mac again?

Smacks own forehead

Gah! I really should have known better than that, so thank you. And yes, I do want it in the trash and not actually deleted. I’d like the files to hang out in the trash for awhile as a last resort should something unexpected happen. I’m managing the trash separately.

I left out a crucial bit when I posted (it should check the md5 of each file in the repeat loop as well), but the whole concept is based on a flawed idea. I thought that I’d be able to get a md5 result from a partial file, and that result just wouldn’t match up until the file was completed. Turns out that running md5 on a partially completed file locks up the process completely. Doh! So…back to the drawing board.

I thought putting it in a timeout block would prevent this. I thought I had set it up so that after two hours, if the md5s were never equal, it would exit the timeout block, skipping the delete function. Is that not the case? If so, how would I accomplish this?

Me too but I’ll be damned if Google and I can find it.

Thanks again to everyone for your input.

Our local linux guy clued me in that there’s actually a built in function in the shell to do exactly what I need. Putting “&&” between two shell commands says “Do A and then Do B but only if A was successful.”

So now my command is a very concise



	try
		do shell script "cp -f " & localFilePath & " " & remoteFilePath & " && rm -f " & localFilePath
	on error
		quit
	end try



So as far as I can tell, if anything goes wrong, the rm command is never run and the script quits. The file will get re-copied the next time the script runs. Viola!

A good way to do it - if the file transfer is interrupted in any way, cp will exit with a non-zero return and the trashing won’t happen. I’m not sure it eliminates the need to check that the transfer was not corrupted, because I don’t know if cp checks that the source and destination files are the same.

Hi Matt

Jacques helped me with a very similar problem regarding moving files from one computer to another
then deleting the original this is pretty much it with your info you will just need to fill in the blanks

tell application "Finder"
	set outFolder to alias blah blah blah "MyFinalFolder" 
	tell (files of folder outFolder whose name is "MyFileOnDT.txt")
		move to alias "ServerVolume"
		delete
	end tell
end tell

I use a variation of this daily now and it works a treat!! (Thanks jacques if your watching!!)