It's almost done...but I can't quite make it alone!

Hi Jacques

You were right! One of the aliases that was in the 2Backup folder didn’t have its original file anymore! As soon as I removed that, the script worked.

The only thing that didn’t work was the ‘do not copy’ part of the script. The script copied all items, even those specified as ‘doNotCopyFiles’. Any ideas on how to fix this?

Regards

Matthew

Here’s the script that I ran:



property doNotCopyFiles : {alias "SystemX:Users:Matt:Documents:General:Miscellaneous:Photoshop Archives:Archives:", alias "SystemX:Users:Matt:Documents:Palm:Users:Matthew Adams:Backups:TT3Update.prc", alias "SystemX:Users:Matt:Documents:Palm:Users:Matthew Adams:Backups:English Dictionary (XLarge).pdb", alias "SystemX:Users:Matt:Documents:Palm:Users:Matthew Adams:Backups:WE 2003 Maps HiRes.prc", alias "SystemX:Users:Matt:Documents:Palm:Users:Matthew Adams:Backups:WE 2003 Info.pdb"}

tell (current date) to tell 100000000 + day * 1000000 + (its month) * 10000 + year as string to tell (text 2 thru 3 & "/" & text 4 thru 5 & "/" & text -4 thru -1) to set {targetFolder, copyname} to {"BackupTest-" & it, "-COPY_" & it}

set backupfolder to "Backup:Scripted Backups"
set Sourcefolder to alias "Backup:2Backup:"

tell application "Finder"
	set original_items to original item of items of Sourcefolder
	tell folder backupfolder
		tell folder targetFolder to if exists then
			tell me to display dialog "Today's backup has already been completed. Are you sure you want to continue & overwrite the existing back up? " buttons {"Continue & overwrite", "Cancel"} default button 2 with icon stop giving up after 15
			delete
		end if
		set targetFolder to make new folder at it with properties {name:targetFolder}
	end tell
	
	repeat with i in original_items
		if i as alias is not in doNotCopyFiles then
			with timeout of 3000 seconds
				set this_item to duplicate i to targetFolder
			end timeout
			tell this_item
				set {this_Name, this_ext} to {name, name extension}
				if this_ext is not "" then
					set name to (text 1 thru -((count this_ext) + 2) of this_Name) & copyname & "." & this_ext
				else
					set name to this_Name & copyname
				end if
			end tell
		end if
	end repeat
end tell


Model: iMac G5 2Ghz
AppleScript: 1.10.3
Browser: Safari 417.8
Operating System: Mac OS X (10.4)

Hi Jacques

Brilliant - it’s fully functional! Thanks so much for your help. The only thing that I had to adjust was to move the the two ‘set moved_Items-x’ lines to after the dialog that asks to overwrite if the script has already been run. Otherwise, it moves the items and if the script gets stopped (ie the decision is made NOT to overwrite), then the items don’t get moved back again.

If I have an alias in the 2Backup folder and its original gets moved/deleted, I’m guessing that the script will return the same erroo as before. Is there anyway to have the script return a dialog box stating what has happened? - ie that an original is ‘missing’?

Regards

Matthew

PS - here’s the script as I have it now - after moving the two ‘move’ lines:



property doNotCopyFilesA : {alias "SystemX:Users:Matt:Documents:General:Miscellaneous:Photoshop Archives:Archives:"}
property doNotCopyFilesB : {alias "SystemX:Users:Matt:Documents:Palm:Users:Matthew Adams:Backups:TT3Update.prc", alias "SystemX:Users:Matt:Documents:Palm:Users:Matthew Adams:Backups:English Dictionary (XLarge).pdb", alias "SystemX:Users:Matt:Documents:Palm:Users:Matthew Adams:Backups:WE 2003 Maps HiRes.prc", alias "SystemX:Users:Matt:Documents:Palm:Users:Matthew Adams:Backups:WE 2003 Info.pdb"}

tell (current date) to tell 100000000 + day * 1000000 + (its month) * 10000 + year as string to tell (text 2 thru 3 & "/" & text 4 thru 5 & "/" & text -4 thru -1) to set {targetFolder, copyname} to {"BackupTest-" & it, "-COPY_" & it}

set backupfolder to "Backup:Scripted Backups"
set Sourcefolder to alias "Backup:2Backup:"
set tempStorageFolder to alias "SystemX:Applications:Temporary Storage:"

tell application "Finder"
	
	set original_items to original item of alias files of Sourcefolder
	tell folder backupfolder
		tell folder targetFolder to if exists then
			tell me to display dialog "Today's backup has already been completed. Are you sure you want to continue & overwrite the existing back up? " buttons {"Continue & overwrite", "Cancel"} default button 2 with icon stop giving up after 15
			delete
		end if
		set backupfolder to make new folder at it with properties {name:targetFolder}
		set moved_Items_1 to move doNotCopyFilesA to tempStorageFolder
		set moved_Items_2 to move doNotCopyFilesB to tempStorageFolder
	end tell
	
	repeat with i in original_items
		with timeout of 3000 seconds
			set this_item to duplicate i to backupfolder
		end timeout
		tell this_item
			set {this_Name, this_ext} to {name, name extension}
			if this_ext is not "" then
				set name to (text 1 thru -((count this_ext) + 2) of this_Name) & copyname & "." & this_ext
			else
				set name to this_Name & copyname
			end if
		end tell
	end repeat
	move moved_Items_1 to alias "SystemX:Users:Matt:Documents:General:Miscellaneous:Photoshop Archives:"
	move moved_Items_2 to alias "SystemX:Users:Matt:Documents:Palm:Users:Matthew Adams:Backups:"
end tell


Hi Jacques

That’s perfect. I decided to go for the option without the ‘choose file’ dialog. I’m guessing that it won’t happen too much (that originals go ‘missing’) and even if they do, I can always locate them manually.

I guess that it would be possible to create a folder similar to the ‘2Backup’ folder to hold aliases of files that weren’t to be copied, rather than listing them in the script. Or would there be problems with this due to the fact that the files would have to be returned to different places after being moved to the temporary storage folder?

I have been through the script and made small notes to myself, explaing what is going on at each stage - just in case I need to adjust the script in the future. The only part that I couldn’t figure out was this part:



repeat with i in these_alias
		try
			set f to original item of i
		on error
			set Missing_Original_items to Missing_Original_items & name of i & return
			set f to {}
		end try
		if f is not {} then
			with timeout of 3000 seconds
				set this_item to duplicate f to backupfolder
			end timeout
			tell this_item
				set {this_Name, this_ext} to {name, name extension}
				if this_ext is not "" then
					set name to (text 1 thru -((count this_ext) + 2) of this_Name) & copyname & "." & this_ext
				else
					set name to this_Name & copyname
				end if
			end tell
		end if
	end repeat

I have never encounted those strange brackets in AppleScript before - what do they do? Also, what is ‘i’?

Anyway, thanks so much for your persistence and help - I’m very grateful.

Regards

Matthew

Hi Jacques

I created a real folder inside the ‘To backup’ folder - I called this folder ‘Do not backup’. Inside there, I placed aliases of items that I didn’t want copied. The aliases were the exact same aliases as listed in previous scripts - 1 folder and 4 files.

I ran the script and it did the copying (and not copying!) and renaming but appeared to produce an error when attempting to return to their original location, the originals of the files who weren’t to be copied. Here is the error code it generated: (this is from the Event Log)

get name of folder “Archives” of folder “Photoshop Archives” of folder “Miscellaneous” of folder “General” of folder “Documents” of folder “Matt” of folder “Users” of startup disk
“Finder got an error: Can’t get name of folder "Archives" of folder "Photoshop Archives" of folder "Miscellaneous" of folder "General" of folder "Documents" of folder "Matt" of folder "Users" of startup disk.”

After this error, the original files (that weren’t to be copied) were found sitting in the ‘Temporary Storage’ folder. Could the fact that the files that aren’t to be copied come from different locations be causing a problem?

Here’s the script as I have it:



set doNotCopyitems to {}
set Missing_Original_items to ""

tell (current date) to tell 100000000 + day * 1000000 + (its month) * 10000 + year as string to tell (text 2 thru 3 & "/" & text 4 thru 5 & "/" & text -4 thru -1) to set {targetFolder, copyname} to {"New Scripted Backup-" & it, "-COPY_" & it}

set backupfolder to "Backup:Scripted Backups"
set Sourcefolder to alias "Backup:To backup:"
set tempStorageFolder to alias "SystemX:Applications:Temporary Storage:"

tell application "Finder"
	set these_alias to alias files of Sourcefolder --these_alias contains items to backup
	repeat with i in (get alias files of folder "Do not backup" of Sourcefolder)
		try
			set end of doNotCopyitems to original item of i --doNotCopyitems contains items to move
		end try
	end repeat
	
	tell folder backupfolder
		tell folder targetFolder to if exists then
			tell me to display dialog "Today's backup has already been completed. Are you sure you want to continue & overwrite the existing back up? " buttons {"Continue & overwrite", "Cancel"} default button 2 with icon stop giving up after 15
			delete
		end if
		set backupfolder to make new folder at it with properties {name:targetFolder}
	end tell
	move doNotCopyitems to tempStorageFolder
	
	repeat with i in these_alias
		try
			set f to original item of i
		on error
			set Missing_Original_items to Missing_Original_items & name of i & return
			set f to {}
		end try
		if f is not {} then
			with timeout of 3000 seconds
				set this_item to duplicate f to backupfolder
			end timeout
			tell this_item
				set {this_Name, this_ext} to {name, name extension}
				if this_ext is not "" then
					set name to (text 1 thru -((count this_ext) + 2) of this_Name) & copyname & "." & this_ext
				else
					set name to this_Name & copyname
				end if
			end tell
		end if
	end repeat
	
	repeat with i in doNotCopyitems -- return items in the original folder
		move (items of tempStorageFolder whose name is (get name of i)) to (container of i)
	end repeat
	
end tell
--this block returns the name of any files/folders whose originals are 'missing'.
if Missing_Original_items is not "" then display dialog "The original file/folder of this alias is missing, and was therefore not backed up. Please correct the link for this file/folder:" & return & Missing_Original_items with icon stop



Can you figure out what is going wrong?

Regards

Matthew

Model: iMac G5 2Ghz
AppleScript: 1.10.3
Browser: Safari 417.8
Operating System: Mac OS X (10.4)