AppleScript - how to move a file from one mac to another?

Hi

I really hope someone can help me!
I have to make a script that everytime a new file is droped in a folder on a mac the script has to send the file to another mac on the same network.
The script I have made is not sending the file to the other mac (I can get it working when I send from one folder to another on the same mac)
How can it be done?

This is my script:

property graphicExtList : {“pdf”}
property myDelay : 5

on adding folder items to this_folder after receiving these_items
tell application “Finder”
set the destination_disk to disk “afp://pdfmacmacintosh:@192.168.1.21/pdfmacmacintosh”
repeat with i from 1 to number of items in these_items
set downloadedFile to item i of these_items
set the theFileInfo to the info for downloadedFile

set oldFileSize to 0
set fileSize to the size of theFileInfo
repeat while fileSize is not equal to oldFileSize
set oldFileSize to fileSize
delay myDelay
set the theFileInfo to the info for downloadedFile
set fileSize to the size of theFileInfo
end repeat

if the name extension of the theFileInfo is in the graphicExtList then
move downloadedFile to destination_disk
end if
end repeat
end tell
end adding folder items to

Hi,

to copy a file to a network volume, the volume must be mounted first.
Then the path to this volume ist just the name of the disk (and its subfolders)

Here is one possible solution:


property graphicExtList : {"pdf"}
property myDelay : 5


on adding folder items to this_folder after receiving these_items
	tell application "Finder"
		set destination_disk to "afp://pdfmacmacintosh:@192.168.1.21/pdfmacmacintosh"
		set disk_name to last word of destination_disk
		if not (exists disk disk_name) then
			try
				mount volume destination_disk
			on error
				display dialog "an error occured while mounting disk " & disk_name
				return
			end try
		end if
		repeat with i in these_items
			set downloadedFile to contents of i as alias
			
			set oldFileSize to 0
			set fileSize to the size of (info for downloadedFile)
			repeat while fileSize is not equal to oldFileSize
				set oldFileSize to fileSize
				delay myDelay
				set fileSize to the size of (info for downloadedFile)
			end repeat
			
			if the name extension of the theFileInfo is in the graphicExtList then
				move downloadedFile to (disk_name as alias)
			end if
		end repeat
	end tell
end adding folder items to

if the file should replace an existing document,
add replacing yes to the move-line

Model: G5 dual 2,5 GHz
Browser: Safari 419.3
Operating System: Mac OS X (10.4)

Thanks a lot, Stefan:D

But maybe I don´t understand or write someting wrong. The volume is called “pdfmacmacintosh” when mounted on my macs desktop. When i try to send a file nothing happens.
I have changed “set disk_name to last word of destination_disk” to “set disk_name to first word of destination_disk” bacause I want the file to be placed in a subfolder.
Is the path wrong? (I have also tried only with “pdfmacmacintosh”)

property graphicExtList : {“pdf”}
property myDelay : 5
on adding folder items to this_folder after receiving these_items
tell application “Finder”
set the destination_disk to “pdfmacmacintosh/Public”
set disk_name to first word of destination_disk
if not (exists disk disk_name) then
try
mount volume destination_disk
on error
display dialog "an error occured while mounting disk " & disk_name
return
end try
end if
repeat with i in these_items
set downloadedFile to contents of i as alias

		set oldFileSize to 0
		set fileSize to the size of (info for downloadedFile)
		repeat while fileSize is not equal to oldFileSize
			set oldFileSize to fileSize
			delay myDelay
			set fileSize to the size of (info for downloadedFile)
		end repeat
		
		if the name extension of the theFileInfo is in the graphicExtList then
			move downloadedFile to (disk_name as alias)
		end if
	end repeat
end tell

end adding folder items to

the path is wrong. AppleScript expects the path separated bei colons
and with a colon at the end if it’s a folder

set the destination_disk to “pdfmacmacintosh:Public:”

and the move-line must be

move downloadedFile to (destination_disk as alias)

Hi Stefan

Still no luck here.
I have tried with “pdfmacmacintosh” and “pdfmacmacintosh:Public:” nothing works!?

Do you have any idea what can go wrong? Thanks again!!!

HTO

two things:

when I shortened the part to get the size of the file
the variable theFileInfo is not defined any more. So change this line:

if name extension of downloadedFile is in the graphicExtList then

the mount volume parameter string must be the complete afp://-address of your first posting
without subfolders of the disk

THANK YOU, Stefan!!! :smiley:
You are a true master of AppleScript!

Just one thing, how can I delete the files from the first mac when they are moved to the second mac?

HTO

it’s just one line. After move downloadedFile to (destination_disk as alias)

move downloadedFile to trash

or to delete it directly

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

Thank you once again!!!
Now it’s just perfect

HTO