I am trying to write a script to backup the entourage database to a mounted afp server. I want to do it in the finder and not via a shell script so it will give the user a progress bar. When i try this script it give me an error
AppleScript Error
Finder got an error: Can’t set “EMPLOYEE_BACKUP:DagelR” to file “Macintosh HD:Users:dagelr:Documents:Microsoft User Data:Office 2004 Identities:Main Identity:Database”.
here is the script
tell application "Finder"
duplicate file "Macintosh HD:Users:dagelr:Documents:Microsoft User Data:Office 2004 Identities:Main Identity:Database" to "EMPLOYEE_BACKUP:DagelR" with replacing
end tell
tell application "Finder"
duplicate the file "Macintosh HD:Users:dagelr:Documents:Microsoft User Data:Office 2004 Identities:Main Identity:Database" to folder "EMPLOYEE_BACKUP:DagelR" with replacing
end tell
the file i want to move is the file called database on my Macintosh HD hard drive into the folder called dagelr on the server mounted called EMPLOYEE_BACKUP into a folder called dagelr.
There are a couple of functions you could use to make the file specifier less rigid, so that if you were later to change your user or startup disk name, the script would still work. One is the ‘path to’ command, which can return the path to your Documents folder:
set docsPath to (path to documents folder as Unicode text) -- Assuming you're running Tiger, or possibly Panther.
tell application "Finder"
duplicate file (docsPath & "Microsoft User Data:Office 2004 Identities:Main Identity:Database") to folder "EMPLOYEE_BACKUP:DagelR" with replacing
end tell
-- Or:
set docsPath to (path to documents folder as Unicode text)
tell application "Finder"
duplicate file "Microsoft User Data:Office 2004 Identities:Main Identity:Database" of folder docsPath to folder "EMPLOYEE_BACKUP:DagelR" with replacing
end tell
Or you could make use of the Finder’s own keyword ‘home’, which represents the current user’s home folder:
tell application "Finder"
duplicate file "Documents:Microsoft User Data:Office 2004 Identities:Main Identity:Database" of home to folder "EMPLOYEE_BACKUP:DagelR" with replacing
end tell
Thanks that worked. One more question. I have the script to this point. It dose what it I want if entourage is open it will close it and it will back up the database. But if entourage is closed, it dose nothing. Where did I go wrong??
tell application "System Events" to get name of current user
set iUser to result
set idev to ":"
set iVolume to "EMPLOYEE_BACKUP"
set ides to iVolume & idev & iUser
tell application "System Events"
if (application process "Microsoft Entourage" exists) then
display dialog "Entourage is running. Entourage must be closed to backup database. Shut down Entourage Now?" buttons {"Cancel", "Quit Now"} default button 2 with icon stop giving up after 40
if button returned of the result is "Quit Now" then
tell application "Microsoft Entourage" to quit
repeat while (application process "Microsoft Entourage" exists)
delay 0.5
end repeat
beep
if (list disks) does not contain iVolume then
display dialog "Enter Network Password" default answer "" with hidden answer
set iPass to the text returned of the result
set iServer to "afp://servername/EMPLOYEE_BACKUP"
open location ("afp://" & iUser & ":" & iPass & "@" & "servername" & "/" & "EMPLOYEE_BACKUP")
delay 5
with timeout of 500000 seconds
tell application "Finder"
duplicate file "Documents:Microsoft User Data:Office 2004 Identities:Main Identity:Database" of home to folder ides with replacing
end tell
end timeout
else
with timeout of 500000 seconds
tell application "Finder"
duplicate file "Documents:Microsoft User Data:Office 2004 Identities:Main Identity:Database" of home to folder ides with replacing
end tell
end timeout
end if
else
-- Do not shutdown Entourage or waited longer than 10 seconds
-- abort Script:
error number -128
end if
else
-- Entrougae is not running
end if
end tell
display dialog "Your Entourage database has been backed up. You may now safely reopen entourage." buttons {"OK"}
A couple of ‘elses’ were in the wrong place. The following version looks OK, but I haven’t been able to test it. Let me know if there are any problems.
tell application "System Events" to get name of current user
set iUser to result
set idev to ":"
set iVolume to "EMPLOYEE_BACKUP"
set ides to iVolume & idev & iUser
tell application "System Events" to set EntourageRunning to (application process "Microsoft Entourage" exists)
if (EntourageRunning) then
display dialog "Entourage is running. Entourage must be closed to backup database. Shut down Entourage Now?" buttons {"Cancel", "Quit Now"} default button 2 with icon stop giving up after 40
if button returned of the result is "Quit Now" then
tell application "Microsoft Entourage" to quit
tell application "System Events"
repeat while (application process "Microsoft Entourage" exists)
delay 0.5
end repeat
end tell
beep
else
-- Do not shutdown Entourage or waited longer than 10 seconds
-- abort Script:
error number -128
end if
end if
-- Entourage is not running at this point.
if (list disks) does not contain iVolume then
display dialog "Enter Network Password" default answer "" with hidden answer
set iPass to the text returned of the result
set iServer to "afp://servername/EMPLOYEE_BACKUP"
open location ("afp://" & iUser & ":" & iPass & "@" & "servername" & "/" & "EMPLOYEE_BACKUP")
delay 5
end if
with timeout of 500000 seconds
tell application "Finder"
duplicate file "Documents:Microsoft User Data:Office 2004 Identities:Main Identity:Database" of home to folder ides with replacing
end tell
end timeout
display dialog "Your Entourage database has been backed up. You may now safely reopen entourage." buttons {"OK"}