Backup by weekday?

I’m trying to write an AppleScript to backup files by the day of the week. For instance on a Monday it would duplicate the contents of a specified folder and put it in the “Monday” folder, or the “Tuesday” folder depending on what day of the week it is. I have this so far but I’m having problems:



if weekday = "Monday" then
	tell application "Finder"
		duplicate file "~:Desktop:test:NEW2.pdf" to "~:Desktop:backup:Thursday" with replacing
	end tell
	
	
else
	
	if weekday = "Tuesday" then
		tell application "Finder"
			duplicate file "~:Desktop:test:NEW2.pdf" to "~:Desktop:backup:Thursday" with replacing
		end tell
		
	else
		
		if weekday = "Wednesday" then
			tell application "Finder"
				duplicate file "~:Desktop:test:NEW2.pdf" to "~:Desktop:backup:Thursday" with replacing
			end tell
		else
			
			if weekday = "Thursday" then
				tell application "Finder"
					duplicate file "~:Desktop:test:NEW2.pdf" to "~:Desktop:backup:Thursday" with replacing
				end tell
			else
				
				if weekday = "Friday" then
					tell application "Finder"
						duplicate file "~:Desktop:test:NEW2.pdf" to "~:Desktop:backup:Thursday" with replacing
					end tell
				end if
			end if
		end if
	end if
end if

But it’s not finding the day of the week, and when I tested just to see if the copy code works, I get this error: Finder got an error: Can’t set “~:Desktop:backup:Thursday” to file “~:Desktop:test:NEW2.pdf”.

I’m sure I’m doing this ALL wrong since I’m new to AppleScript… but I need some help! Thanks.

Your file and folder paths are malformed and you’ve omitted the word ‘folder’ before the destination path. Also, ‘weekday’ is a reserved word, so you can’t use it as a variable name.

Mac OS paths should begin with the disk (volume) name and proceed from there. However, the Finder assumes that any path that doesn’t begin with the name of a mounted volume begins at the desktop, so you could simplify the script to:

set wkday to (weekday of (current date)) as string
tell application "Finder"
  duplicate file "test:NEW2.pdf" to folder ("backup:" & wkday) with replacing
end tell

This assumes, of course, that the folders will be on the desktop when the script’s finally in use and that all the necessary folders and files will already exist. :slight_smile:

I got it!! AWESOME THANKS!

Is it possible to set a exact time of the day for the backup process? Thank You.

Jeff

Thanks for the improved AppleScript Syntax, however, how does one describe the full path? I want to backup my “Database” Entourage File which must remain in my ~:Documents:Microsoft User Data:Office 2004 Identities:Main Identity folder. I keep getting syntax errors.

Trying:
tell application “Finder”
duplicate file “~:Documents:Microsoft User Data:Office 2004 Identities:Main Identity:Database” to “~:Desktop:SyncFiles:Database” with replacing
end tell

Gives the following error: Finder got an error: Can’t set “~:Desktop:SyncFiles:Database” to file “~:Documents:Microsoft User Data:Office 2004 Identities:Main Identity:Database”.

Your responses are appreciated.
Grace

I’m not well versed in POSIX paths, but I think you probably want:

tell application "Finder"
  duplicate file "Documents:Microsoft User Data:Office 2004 Identities:Main Identity:Database" of home to folder "SyncFiles" of desktop with replacing
end tell

The destination of a ‘duplicate’ command is the container where you want the duplicate to appear. The duplicate will automatically be given the same name as the source item. All paths should be preceded by the word ‘folder’, ‘file’, or ‘item’, as appropriate.