I have a script that does some backup of a few files prior to my doing my backups. I call it my Pre Backup Script. This is it below.
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
The problem with this script (ever since I upgraded to Sonoma from Monterey is that the notification no longer goes away as it did after a couple of seconds in Monterey.
So, I found this script that dismisses notifications, and it works just fine fine, when run on its own. Found it here: AppleScript to close all notifications on macOS Big Sur, Monterey, and Ventura · GitHub, almost all the way down the page in a September 20th post by “bpetrynski”.
-- macOS 15 Sequoia
-- Set of close action phrases in multiple languages
property closeActionSet : {"Close", "Clear All", "Schließen", "Alle entfernen", "Cerrar", "Borrar todo", "关闭", "清除全部", "Fermer", "Tout effacer", "Закрыть", "Очистить все", "إغلاق", "مسح الكل", "Fechar", "Limpar tudo", "閉じる", "すべてクリア", "बंद करें", "सभी हटाएं", "Zamknij", "Wyczyść wszystko"}
-- Function to perform close action on a given element
on closeNotification(elemRef)
tell application "System Events"
try
set theActions to actions of elemRef
repeat with act in theActions
if description of act is in closeActionSet then
perform act
return true
end if
end repeat
end try
end tell
return false
end closeNotification
-- Function to recursively search for and close notifications
on searchAndCloseNotifications(elemRef)
tell application "System Events"
-- If the element has subelements, search them first
try
set subElements to UI elements of elemRef
repeat with subElem in subElements
if my searchAndCloseNotifications(subElem) then
return true
end if
end repeat
end try
-- Try to close the current element if it's a notification
if my closeNotification(elemRef) then
return true
end if
end tell
return false
end searchAndCloseNotifications
-- Main script to clear notifications
on run
tell application "System Events"
if not (exists process "NotificationCenter") then
log "NotificationCenter process not found"
return
end if
tell process "NotificationCenter"
if not (exists window "Notification Center") then
log "Notification Center window not found"
return
end if
set notificationWindow to window "Notification Center"
-- Main loop to clear notifications
repeat
try
if not my searchAndCloseNotifications(notificationWindow) then
-- If no notifications were closed, we're done
exit repeat
end if
-- Reduced delay to speed up the script
delay 0.1
on error errMsg
-- If an error occurs, log it and exit the loop
log "Error: " & errMsg
exit repeat
end try
end repeat
end tell
end tell
end run
To make things simple, I tried just adding this script to my Pre Backup Script, but end up getting an error (see screenshot).
Anyone have any ideas on how to resolve this?