Log + Copy Script


I don’t have much experience with AppleScript and I would like to do the following:

I would need a script that will log me into another computer in my local area network, go to a specific folder and copy to my local machine some predefined files.

At the end of the process, if everything went OK, I need to display a message that says the script completed successfully. In case of an error I need to stop the script and display the error.

Can someone help me out with all this?

Thanks in advance.

Andrew Hobson

How are you intending to do this? Via scp? or mounting a sharepoint and doing the copy that way?

I need to mount a sharepoint from a MacOS 10.4.10 machine.

Andrew Hobson

Hi Andrew,

something like this

	mount volume "afp://user:pass@NetworkComputer.local/theVolume"
	set DestFolder to choose folder with prompt "choose destination folder"
	set theFiles to choose file with prompt "choose files to copy" with multiple selections allowed without invisibles
	tell application "Finder" to move theFiles to DestFolder
	display dialog "" buttons {"Done"} default button 1
on error e number n
	if n is -35 then display dialog "Couldn't mount volume" buttons {"Cancel"} default button 1
	display dialog "Error: " & e buttons {"Cancel"} default button 1
end try

Of course you can hard-code the destination folder like

set DestFolder to alias ((path to documents folder as Unicode text) & "myFolder:")

I have some more questions…

  1. If I use the command “mount volume”, is there a command to “unmount” the volume once the copy is done? If yes, could you give me an example please?

  2. Is the syntax of this script correct? Because I don’t understand why some times you need to add: as string or use the term alias…

set SourceFolder to “MacOS X:Clients:CPE”
set DestFolder to “MacOS X:Clients:Bidon”

tell application “Finder”
duplicate (every file of folder SourceFolder) to folder DestFolder with replacing
end tell

Thanks for your help.

Andrew Hobson

there is no AppleScript command, but you can use the shell

do shell script "diskutil unmount /Volumes/theVolume"

yes, the syntax is correct (although a path which points to a folder should end with a colon, and the parentheses are not needed)
You have string paths and you use the keyword folder as a folder specifier

you can use also

set SourceFolder to alias "MacOS X:Clients:CPE:"
set DestFolder to alias "MacOS X:Clients:Bidon:"

tell application "Finder"
	duplicate every file of SourceFolder to DestFolder with replacing
end tell