Hi
I’m a relative newcomer to the world of AppleScript, and I can’t figure this out despite lots of searching…so I’m hoping that someone can help me.
I’m trying to refine my backup script which is triggered by a script that runs on startup. If this script detects that it’s a Tuesday (for example), it executes another script which actually does the backup. The problem is, if I start the computer for a second time on the same Tuesday, it backup script attempts to run again - however the backup has obviously already been created. Here’s my attempt to get the script to check to see if the backup folder has already been created - and if so, to ask if it should be run again.
The problem is that when the script detects that the backup folder already exists, it doesn’t present the ‘run again?’ dialog box - it just says that there’s an error because the file already exists.
Any one know how to fix this?
Thanks!
Matthew
– Get system date and convert it to mm–dd–yy format –
set todaysDate to (current date)
set {d, m, y} to {day, month, year} of todaysDate
set monthList to {January, February, March, April, May, June, ¬
July, August, September, October, November, December}
repeat with i from 1 to 12
if m = (item i of monthList) then
set monthString to text -2 thru -1 of (“0” & i)
exit repeat
end if
end repeat
set dayString to text -2 thru -1 of (“0” & d)
set todaysDate to dayString & “/” & monthString & “/” & y
– end date procedure –
set backupfolder to “BackupTest-” & todaysDate
– Create a backup folder on the Desktop –
tell application “Finder”
activate
make new Finder window to disk “Backup”
set target of Finder window 1 to folder “Scripted Backups” of disk “Backup” --opens window of folder where backup will be/is
if not (folder (backupfolder) exists) then
make new folder at folder “Scripted Backups” of disk “Backup” with properties {name:backupfolder} --if the backup hasn’t already been actioned, the script makes a new backup folder with date string attached at backup location
set target of Finder window 1 to folder "Scripted Backups" of disk "Backup"
else if (folder (backupfolder) exists) then --PROBLEM HERE!! This should check to see if the backup has already been run and if it has, it will discover that the backup folder with date string already exists. But it's not working - I just get an error saying 'an item with that name already exists..."
display dialog "The backup for today has already been actioned. Backing up again will overwrite files. Continue anyway?" buttons {"Yes", "No"} default button 2
set the button_pressed to the button returned of the result
if the button_pressed is "No" then display dialog "Ok, thanks." & (beep)
if the button_pressed is "Yes" then tell application "Finder"
delete folder (backupfolder) of folder "Scripted Backups" of disk "Backup"
open file "TV instructions.doc" of desktop --this is just a trigger to illustrate to me that the script is working. When functioning correctly, this line will activate a separate backup script.
end tell
end if
end tell
Model: iMac G5 2Ghz
AppleScript: 1.10.3
Browser: Safari 417.8
Operating System: Mac OS X (10.4)