Newbie to script (in fact to Apple)


last week a head of a dept. placed 2 Mac’s (OSX10.5 if I’m correct) with Final Cut on it. Users should work with FCP and use their personal external harddisk because of the necessary diskspace. When I asked if there was some kind of back-up he answered “not necessary, it’s Apple” (well … in fact the disks are LaCie, but never mind this ignorancy).

Determined not to let these users down if the external disk crashes I want to write a script which copies the content of their projectfolder to the Macintosh users\documents\subfolder.

Could anyone help me on writing the next script?

User starts the script as soon as (s)he is ready working on it for that day and fills in the foldername of his/her project.
These folders are always on the LaCie external drive:\Final Cut Projects{Projectfoldername}

The script then copies the content to MacintoshHD\username\Documents\backup{Projectfoldername}

If this {Projectfoldername} on the MacintoshHD is new, the script should create it and then copy the content into it.

If it is not new, already saved files should be overwritten without any warning.

If the foldername the user has entered is not on the LaCie disk, it should warn the user and end the script.

I would much appreciate any help … and in the end, the users will too.
(Though a crash would be welcome to have a look at the face of the head of that dept.)



especially LaCie disks aren’t the most reliable ones.
And unfortunately data loss is cross platform :wink:

The easiest way to make a backup on OS X is to use the shell command rsync, which is very powerful.
The following script asks the user to choose the source folder of one of the folders in the project folder
and does the backup to the equivalent folder in ~/Documents/backup/.
Only new or changed files will be copied.
Deleted files in the source folder will also be deleted in the destination folder.
The script displays a message both on success and on error.

Please change the name of the disk in the first line from LaCie into the proper name

set sourceBaseFolder to "LaCie:Final Cut Projects:"
set destinationBaseFolder to ((path to documents folder as text) & "backup:")

tell application "Finder"
	set allProjectFolders to name of folders of folder sourceBaseFolder
	set projectFolder to choose from list allProjectFolders with prompt "choose project folder"
end tell
if projectFolder is false then return

set sourceFolder to quoted form of (POSIX path of sourceBaseFolder & item 1 of projectFolder)
set destinationFolder to quoted form of POSIX path of destinationBaseFolder

	do shell script "/bin/mkdir -p " & destinationFolder & ";/usr/bin/rsync -atE --delete " & sourceFolder & space & destinationFolder
	display dialog "Backup done" buttons {"OK"} default button 1
on error e
	display dialog "Error " & e & "occured" buttons {"OK"} default button 1
end try

:rolleyes: thanks Stefan.

I’m going to try this one out tomorrow (if I can get behind one of the machines without him noticing it…) :lol:

Note that 10.5 comes with the user friendly backup system: Time Machine.

Right, but the OP wants to backup from external to internal and no incremental backup :wink:

OP? That’s me, but what is an OP?

original poster

Hi Stefan,

The script works fine, thanks a lot.

Is there a way that I can make the dialogbox at the end visible on the front?
(display dialog “Backup done” buttons {“OK”} default button 1)

Even if I have no applications running and I see the desktop, I don’t see the dialog ‘backup done’ appear. Only the script-icon is jumping on the screen, desperately needing attention. :o

When I click it, the dialog appears.

Tell the Finder to display the dialog:

   Tell application "Finder" to display dialog "Backup done" buttons {"OK"} default button 1