File sync script--comments?
File sync script--comments?
- Subject: File sync script--comments?
- From: Phil Brodd <email@hidden>
- Date: Tue, 24 Jul 2001 11:36:09 -0500
Hi everyone,
Some friends and I enjoy playing Unreal Tournament, and we use a program
called "Synchronize!" to keep all of our maps and such things in sync. This
is semi-tedious to do manually, so I wrote a script to handle it. I'd
appreciate any suggestions from the list on how it could be better.
I've been AppleScripting for a while now, but I don't think I do things very
idiomatically. In particular, I think the way I set up paths in the
beginning is ugly. Is there a better way to do it? Is there a way that
would be more easily portable from machine to machine? Any comments are
welcome.
Thanks!
Phil
======================================
set only_Testing to false
set xxx_Is_Online to true
set startup_disk to (path to startup disk as string)
set local_unreal_container to "Applications (Mac OS 9):"
set unreal_system_folder to startup_disk & local_unreal_container & "Unreal
Tournament:System:"
set unreal_ini to alias (unreal_system_folder & "UnrealTournament.ini")
set backup_folder to ((path to system folder as string) & "Sync:")
set unreal_ini_backup to ((path to system folder as string) &
"Sync:UnrealTournament.ini")
display dialog ,
"Should I preserve your \"UnrealTournament.ini\" or sync it with the
server's copy?" buttons ,
{"Quit", "Sync it", "Leave it alone"} default button 1
set ini_preference to the button returned of the result
if ini_preference is "Quit" then
-- bail out
error number -128
else
-- back up the ini file
tell application "Finder"
duplicate file unreal_ini to folder backup_folder with replacing
end tell
end if
try
if (list disks) does not contain "xxxx" then
mount volume "rocket_science" on server ,
"xxxx" in AppleTalk zone "xxxx" as user name ,
"xxxx" with password "xxxx"
set sync_server_is_mounted to true
end if
if not only_Testing then
set sync_files_location to ((path to system folder as text) &
"Sync:")
set the_folders to {alias (sync_files_location & "utx") ,
, alias (sync_files_location & "unr") ,
, alias (sync_files_location & "umx") ,
, alias (sync_files_location & "uax") ,
, alias (sync_files_location & "sys")}
-- Syncing can take longer than AppleScript's default timeout.
-- Give it 120 minutes!
try
tell application "Synchronize!"
with timeout of 7200 seconds
repeat with this_folder in the_folders
activate
sync this_folder
end repeat
quit
end timeout
end tell
on error errMsg number errNum
if errNum is -1712 then
-- two hours was not long enough!
display dialog ,
"Wow, two hours was not long enough to complete the
sync! I'm going to bail out." buttons {"OK"} ,
default button 1
error number -128
end if
end try
end if
if ini_preference is "Leave it alone" then
tell application "Finder"
move file unreal_ini_backup to folder unreal_system_folder with
replacing
end tell
else if ini_preference is "Sync it" then
tell application "Finder"
delete file unreal_ini_backup
end tell
end if
if xxx_Is_Online then
try
tell application "Finder"
put away item "xxxxxx" of desktop
end tell
on error errorMessage number errorNumber
display dialog "The sync server wasn't mounted?
I'm sorry, but it's probably your fault." buttons {"OK"} default
button 1
-- bail out
error number -128
end try
end if
on error errorMessage number errorNumber
-- AFP No Server error number is "-5016"
if errorNumber is -5016 then
display dialog "I can't mount the sync server! Is xxx's file
sharing enabled?
Suggestion: Throw a foam rubber object at xxx." buttons {"OK"} default
button 1
end if
tell application "Finder"
delete file unreal_ini_backup
end tell
if sync_server_is_mounted then
tell application "Finder"
put away item "xxxxx" of desktop
end tell
end if
-- bail out
error number -128
end try