Backup Script

Hi, I’ve been trying this for a few hours now with little to no success. What I want the script to do is create a folder inside the backup folder of the disk “THE BACK FORTY” (my father’s firewire 40 gig), and name the file with the current date. I’ve browsed the forum looking for examples and got andy_boretto’s example copied over to my own script. It looks as follows:

tell application "Finder"
	set file_location to "THE BACK FORTY:Backup:" as string
	set folder_name to do shell script "date +%m/%d/%y" as string
	set file_path to ((file_location as string) & folder_name & ":") as string
	make new folder at file_location with properties {name:"TEMP"}
	set file_alias to ("THE BACK FORTY:Backup:TEMP") as alias
	set name of file_alias to file_path
end tell

Whenever I try to run it, I get an error saying “The Finder got an error: the operation could not be completed.”

Can someone please explain to me what’s going wrong, because it’re pretty obvious that neither the Finder nor the Script Editor are so forthcoming.

P.S.: How would I have the script check for and delete any existing TEMP folder (from say, an aborted script execution) before the rest of the operation begins?

Thanks so much
Charles

One thing that is likely to cause problems is where the script is trying to set the name of something to “THE BACK FORTY:Backup:08/23/03:”.

set name of file_alias to file_path

That won’t be allowed because colons are used in file and folder paths. Does this do what you want?

set file_location to "THE BACK FORTY:Backup:"
set folder_name to do shell script "date +%m/%d/%y"
set file_path to ((file_location as string) & folder_name & ":")
set file_alias to ("THE BACK FORTY:Backup:TEMP") as alias

tell application "Finder"
	make new folder at folder file_location with properties {name:"TEMP"}
	set name of file_alias to folder_name
end tell

– Rob

Well, as originally entered, it didn’t work, but I shifted it around like so:

tell application "Finder"
	make new folder at folder "THE BACK FORTY:Backup:" with properties {name:"TEMP"}
end tell

set file_location to "THE BACK FORTY:Backup:"
set folder_name to do shell script "date +%m/%d/%y"
set file_path to ((file_location as string) & folder_name & ":")
set file_alias to ("THE BACK FORTY:Backup:TEMP") as alias

tell application "Finder"
	set name of file_alias to folder_name
end tell

And it works. Thanks so much for the help!

To check for an existing file or folder:

set path_ to "path:to:item"

tell application "Finder"
	if exists alias path_ then
		-- do something to alias path_
	end if
end tell

– Rob

Charles, you may want to be careful when using slashes in a folders name…

You can use something different to seperate the date format like dashes or underscores, like this…

set folder_name to do shell script "date +%m-%d-%y"
set folder_name to do shell script "date +%m_%d_%y"
--> 08-23-03 or 08_23_03

If you drag a folder/file named 08/23/03 onto an open terminal app window you’ll see that it will turn your slashes into colons like so…

08:23:03

Since colons and slashes are used for the paths of items, this may cause problems.