"Robocopy" Script

Hello Guys,

I’m new to apple scripting and tried beginning on my own. I googled for hours before I found MacScripter and I did not find nothing coming close to this.

Here is what I need to create:
“Robocopy” application from server to the desktop. The file should have a new date and the script needs to able to identify this in order to copy the new file and replace the old one.

Details:
From time to time we upgrade one of our software and the software client needs to be replaced in order to work with the new database(Oracle).

The software client is stored in a server and each user would “connect to server” using SMB. I just need to create a script that could actually see the up-to-date file and replace the old file on the desktop.

Note: Each user auto-mounts a folder from the server on startup of their computer.

Which route should I go? Could Automator do this as well?

Thank you!

I guess I’m SOL here?

I’m looking for a small scriptable program that will do something like this for example:

copy application file from \Server\dirname\ to \desktop but with additional switches like:

  • replace existing data only if source file modification date is newer than destination - otherwise skip

There’s got to be something like this for Mac OS X since it’s got Unix under the hood.

Thanks!

Hi,

something like this?


property fileName : "appFile.app"
property serverName : "server"
property serverPath : "path:to:directory:"

tell application "Finder"
	if exists disk serverName then
		set sourceFile to file (serverName & ":" & serverPath & fileName)
		if exists sourceFile then
			set destinationFile to file fileName of desktop
			if (not (exists destinationFile)) or (modification date of sourceFile comes after modification date of destinationFile) then
				duplicate sourceFile to desktop replacing yes
			end if
		end if
	end if
end tell

Hello StefanK,

Thank you for your feedback.

Each user auto-mounts a folder from the server on startup of their computer.

smb://123.123.1.1/Folder/FOLDER2

The software.app file will be available on FOLDER2.

Does it look correct to you? Basically the script need to locate the .app file on the server, verify the modification date and replace de old file on the Desktop.

The script you provided looks about right, I just don’t know if I need to change anything. When I run, it says:
tell application “Finder”
exists disk “smb://123.123.1.1”
→ false
End tell

Here is how the script looks like:

property fileName : “software.app”
property serverName : “smb://123.123.1.1”
property serverPath : “/Folder/FOLDER2:”

tell application “Finder”
if exists disk serverName then
set sourceFile to file (serverName & “:” & serverPath & fileName)
if exists sourceFile then
set destinationFile to file fileName of desktop
if (not (exists destinationFile)) or (modification date of sourceFile comes after modification date of destinationFile) then
duplicate sourceFile to desktop replacing yes
end if
end if
end if
end tell

serverName must match the name as it appears on the desktop or in /Volumes without the filesystem scheme (smb://)
serverPath is the HFS path (colon separated) minus the server name with a trailing colon

property serverName : "123.123.1.1"
property serverPath : "Folder:FOLDER2:"

StefanK

I’ve changed the servername and the server path as you suggested and it worked.

I just need to tweak a little bit now.

How could I tell the script to copy the “software.app” file even though the file does not exist on the desktop?

The script has the following:

set destinationFile to file fileName of desktop
            if (not (exists destinationFile)) or (modification date of sourceFile comes after modification date of destinationFile) then
                duplicate sourceFile to desktop replacing yes

Thank you!

The script does copy the “software.app” file even though the file does not exist on the desktop

Hello,

What If I just want to copy the file from SourceFile and replace the desktop file without the modification date?

Does it looks right? I tested and it did copy the file over…


property fileName : "Louise.app"
property serverName : "LouiseClient"
property serverPath : "Client:MAC:"

tell application "Finder"
	if exists disk serverName then
		set sourceFile to file (serverName & ":" & serverPath & fileName)
		if exists sourceFile then
			set destinationFile to file fileName of desktop
			duplicate sourceFile to desktop replacing yes
		end if
	end if
	
end tell


For some reason it does not copy the .app file properly.

When I drag and drop it manually the software works.

When I launch the script, the script does the drag and drop job but at some point the software gets corrupted during the transfer.

Any thoughts?

Why not use “rdist” which will do the job? This web site has a good description of it…