Just a Question

In a past post, I included this script.

tell application id "com.apple.Finder" to duplicate file POSIX file ¬
	"/Users/homer/Library/Thunderbird/Profiles/7jyt1da7.default-release/abook.sqlite" to the folder ¬
	POSIX file "/Users/homer/Documents/MacBook Pro Specific/Address Book Sync" with replacing

tell application id "com.apple.Finder" to duplicate file POSIX file ¬
	"/Users/homer/Library/Thunderbird/Profiles/7jyt1da7.default-release/history.sqlite" to the folder ¬
	POSIX file "/Users/homer/Documents/MacBook Pro Specific/Address Book Sync" with replacing

tell application id "com.apple.Finder" to duplicate file POSIX file ¬
	"/Users/homer/Library/Application Support/Firefox/Profiles/jla842kt.default-release/bookmarks.html" to the folder ¬
	POSIX file "/Users/homer/Documents/MacBook Pro Specific/Firefox Bookmarks Sync" with replacing

tell application id "com.apple.Finder" to duplicate file POSIX file ¬
	"/Users/homer/Library/Application Support/Firefox/Profiles/jla842kt.default-release/favicons.sqlite" to the folder ¬
	POSIX file "/Users/homer/Documents/MacBook Pro Specific/Firefox Bookmarks Sync" with replacing

tell application id "com.apple.Finder" to duplicate file POSIX file ¬
	"/Users/homer/Library/Application Support/Firefox/Profiles/jla842kt.default-release/places.sqlite" to the folder ¬
	POSIX file "/Users/homer/Documents/MacBook Pro Specific/Firefox Bookmarks Sync" with replacing

tell application id "com.apple.Finder" to duplicate folder POSIX file ¬
	"/Users/homer/Library/Application Support/ChronoSync/Tasks" to the folder ¬
	POSIX file "/Users/homer/Documents/MacBook Pro Specific/Backup Scripts/ChronoSync Tasks" with replacing

tell application id "com.apple.Finder" to duplicate folder POSIX file ¬
	"/Users/homer/Library/Application Support/XMenu/Custom" to the folder ¬
	POSIX file "/Users/homer/Documents/MacBook Pro Specific/XMenu Sync" with replacing

tell application id "com.apple.Finder" to duplicate folder POSIX file ¬
	"/Users/homer/Library/Application Support/SpamSieve" to the folder ¬
	POSIX file "/Users/homer/Documents/MacBook Pro Specific/SpamSieve Backup" with replacing

tell application id "com.apple.Finder" to duplicate file POSIX file ¬
	"/Users/homer/Library/Preferences/com.c-command.SpamSieve.plist" to the folder ¬
	POSIX file "/Users/homer/Documents/MacBook Pro Specific/SpamSieve Backup/Preference File" with replacing

tell application id "com.apple.Finder" to duplicate file POSIX file ¬
	"/Users/homer/Library/Application Scripts/com.apple.mail/Apple Mail - Remote Training.scpt" to the folder ¬
	POSIX file "/Users/homer/Documents/MacBook Pro Specific/SpamSieve Backup/AppleScript" with replacing

display notification "Completed Successfully!" with title "Pre Backup AppleScript"

delay 1

Then Robert Fern posted this, saying he had cleaned up my script by consolidating it into 1 tell block.

tell application id "com.apple.Finder"
	duplicate POSIX file ¬
		"/Users/homer/Library/Thunderbird/Profiles/7jyt1da7.default-release/abook.sqlite" to the POSIX file "/Users/homer/Documents/MacBook Pro Specific/Address Book Sync" with replacing
	
	duplicate POSIX file ¬
		"/Users/homer/Library/Thunderbird/Profiles/7jyt1da7.default-release/history.sqlite" to the POSIX file "/Users/homer/Documents/MacBook Pro Specific/Address Book Sync" with replacing
	
	duplicate POSIX file ¬
		"/Users/homer/Library/Application Support/Firefox/Profiles/jla842kt.default-release/bookmarks.html" to the POSIX file "/Users/homer/Documents/MacBook Pro Specific/Firefox Bookmarks Sync" with replacing
	
	duplicate POSIX file ¬
		"/Users/homer/Library/Application Support/Firefox/Profiles/jla842kt.default-release/favicons.sqlite" to the POSIX file "/Users/homer/Documents/MacBook Pro Specific/Firefox Bookmarks Sync" with replacing
	
	duplicate POSIX file ¬
		"/Users/homer/Library/Application Support/Firefox/Profiles/jla842kt.default-release/places.sqlite" to the POSIX file "/Users/homer/Documents/MacBook Pro Specific/Firefox Bookmarks Sync" with replacing
	
	duplicate POSIX file ¬
		"/Users/homer/Library/Application Support/ChronoSync/Tasks" to the POSIX file "/Users/homer/Documents/MacBook Pro Specific/Backup Scripts/ChronoSync Tasks" with replacing
	
	duplicate POSIX file ¬
		"/Users/homer/Library/Application Support/XMenu/Custom" to the POSIX file "/Users/homer/Documents/MacBook Pro Specific/XMenu Sync" with replacing
	
	duplicate POSIX file ¬
		"/Users/homer/Library/Application Support/SpamSieve" to the POSIX file "/Users/homer/Documents/MacBook Pro Specific/SpamSieve Backup" with replacing
	
	duplicate POSIX file ¬
		"/Users/homer/Library/Preferences/com.c-command.SpamSieve.plist" to the POSIX file "/Users/homer/Documents/MacBook Pro Specific/SpamSieve Backup/Preference File" with replacing
	
	duplicate POSIX file ¬
		"/Users/homer/Library/Application Scripts/com.apple.mail/Apple Mail - Remote Training.scpt" to the POSIX file "/Users/homer/Documents/MacBook Pro Specific/SpamSieve Backup/AppleScript" with replacing
end tell
display notification "Completed Successfully!" with title "Pre Backup AppleScript"

delay 1

So here’s my question. Can you also consolidate “try” scripts (see below script)?

tell application "Finder"
	try
		set theFolderAlias to alias "Volumes:MacBook Pro Local Backups:Sync Folders Local Backups:Local Documents Archive:"
		delete (get items of theFolderAlias whose creation date < ((current date) - 90 * days))
	end try
	
	try
		set theFolderAlias to alias "Volumes:MacBook Pro Local Backups:Sync Folders Local Backups:Local Dropbox Folders Archive:"
		delete (get items of theFolderAlias whose creation date < ((current date) - 90 * days))
	end try
	
	try
		set theFolderAlias to alias "Volumes:MacBook Pro Local Backups:Sync Folders Local Backups:Local Installs Archive:"
		delete (get items of theFolderAlias whose creation date < ((current date) - 90 * days))
	end try
	
	try
		set theFolderAlias to alias "Volumes:MacBook Pro Local Backups:Sync Folders Local Backups:Local Movies Archive:"
		delete (get items of theFolderAlias whose creation date < ((current date) - 90 * days))
	end try
	
	try
		set theFolderAlias to alias "Volumes:MacBook Pro Local Backups:Sync Folders Local Backups:Local Music Archive:"
		delete (get items of theFolderAlias whose creation date < ((current date) - 90 * days))
	end try
	
	try
		set theFolderAlias to alias "Volumes:MacBook Pro Local Backups:Sync Folders Local Backups:Local Photos Archive Archive:"
		delete (get items of theFolderAlias whose creation date < ((current date) - 90 * days))
	end try
	
	try
		set theFolderAlias to alias "Volumes:MacBook Pro Local Backups:Sync Folders Local Backups:Local Pictures Archive:"
		delete (get items of theFolderAlias whose creation date < ((current date) - 90 * days))
	end try
end tell

delay 3

tell application "Finder"
	empty trash
end tell

It depends.
If the first command fails, do you want the script to continue to the second command?

Ideally, I would like to have the script stop and tell me where the failure occurred. But, if there’s one thing I’ve learned here, it’s that sometimes, you just need to leave well enough alone. The script works and works well. I’d hate to have you spend a lot of time modifying it, when it’s fine the way it is.

Just put them all in one try block

That was easy, thank you.

try this…

repeat with subfolder in {"Documents Archive:", "Dropbox Folders Archive:", "Installs Archive:", "Movies Archive:", "Music Archive:", "Photos Archive Archive:", "Pictures Archive:"}
	try
		tell application "Finder"
			set theFolderAlias to alias ("Volumes:MacBook Pro Local Backups:Sync Folders Local Backups:Local " & subfolder)
			delete (get items of theFolderAlias whose creation date < ((current date) - 90 * days))
		end tell
	on error
		exit repeat
	end try
end repeat

delay 3

tell application "Finder"
	empty trash
end tell

Now that is one slick script, and I can adapt it to another backup routine (that doesn’t have automatic old file deletion) as well. Just a curiosity, the “on error exit repeat” part stops the script from going forward as soon as an error is encountered, correct?

You are correct! (Extra characters to get past limit)

Spoke too soon. The latest folder that I have in any of the “Archive” folders is November 27th, 2024. So, just for testing, I changed the days from 90 to 89. Ran the script and nothing was deleted, and no error as well. I went through your script pretty thoroughly a couple of times, and it should work. Anything you need from me as to how things are setup?

here is a slightly modified version that makes the list’s strings smaller

repeat with subfolder in {"Documents", "Dropbox Folders", "Installs", "Movies", "Music", "Photos Archive", "Pictures"}
	try
		tell application "Finder"
			set theFolderAlias to alias ("Volumes:MacBook Pro Local Backups:Sync Folders Local Backups:Local " & subfolder & " Archives:")
			delete (get items of theFolderAlias whose creation date < ((current date) - 90 * days))
		end tell
	on error
		exit repeat
	end try
end repeat

delay 3

tell application "Finder"
	empty trash
end tell

Still nothing. Rather than have you take any more time on this, maybe I’ll just stick with the “one try” approach. That has really compacted the scripts, so I’m good.