Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

bogdanw

macrumors 604
Original poster
Mar 10, 2009
6,749
3,456
I recently created some web apps using Safari on macOS Sequoia and I was surprised that there isn’t an easy way to delete all the files and folders one such app creates.
Apple’s documentation simply says “drag the web app to the Trash”.
Apple Support - Use Safari web apps on Mac https://support.apple.com/104996
Apps like AppCleaner and Pearcleaner don’t find all related files or folders. (see video)

As each web app created by Safari has a unique identifier (UUID), I created an AppleScript that can select a web app, search the user’s home folder for files and folders that have the UUID in their name and offers the option to delete them all or one by one. As the script uses Finder to delete the items, all can be put back from Trash in their original location, it you change your mind about deleting them :)

Give Script Editor (/Applications/Utilities/Script Editor.app) Full Disk Access before running the script:

AppleScript:
-- AppleScript that searches for files or folders associated with a web app created by Safari on macOS Sonoma or later
-- Apple Support - Use Safari web apps on Mac https://support.apple.com/104996

set theApp to choose file with prompt "Please select an application from ~/Applications :" of type {"app"}
set appPath to (POSIX path of theApp)
set infoPath to (POSIX path of theApp & "/Contents/Info.plist") as text
set theID to do shell script "/usr/libexec/PlistBuddy -c 'Print LSTemplateApplicationParameters:TemplateAppUUID' " & infoPath
set theList to (do shell script "find ~/ -iname '*" & theID & "*'")

-- alternative command that excludes ~/.Trash from search
--set theList to (do shell script "find ~/ -iname '*" & theID & "*' | grep -Evw '(.Trash)'")

display dialog ("The following were found:
" & theList) buttons {"Delete items", "Cancel"} default button 1
if button returned of result = "Cancel" then
    return
else
    set thePrgs to paragraphs of theList
    set FilesFolders to {}
    repeat with i from 1 to count of thePrgs
        set end of FilesFolders to POSIX file (item i of thePrgs)
    end repeat
    set question to display dialog "Do you want to delete" buttons {"All", "One by one", "Cancel"} default button 1
    set answer to button returned of question
    if answer is equal to "All" then
        tell application "Finder"
            repeat with currentItem in FilesFolders
                try
                    tell application "Finder"
                        delete currentItem
                    end tell
                on error
                    display dialog ("Item could not be deleted") buttons {"OK"}
                end try
            end repeat
        end tell
    end if
    
    if answer is equal to "One by one" then
        tell application "Finder"
            repeat with currentItem in FilesFolders
                set question to display dialog "Do you want to delete" & (POSIX path of currentItem) buttons {"Yes", "No", "Cancel"} default button 1
                set answer to button returned of question
                if answer is equal to "Yes" then
                    try
                        tell application "Finder"
                            delete currentItem
                        end tell
                    on error
                        display dialog ("Item could not be deleted") buttons {"OK"}
                    end try
                end if
                if answer is equal to "Cancel" then
                    return
                end if
            end repeat
        end tell
    end if
    
    if answer is equal to "Cancel" then
        return
    end if
end if

activate
set question to display dialog "Delete the app " & appPath buttons {"Yes", "No"} default button 1
set answer to button returned of question
if answer is equal to "Yes" then
    try
        tell application "Finder"
            delete theApp
        end tell
    on error
        display dialog ("App could not be deleted") buttons {"OK"}
    end try
end if
if answer is equal to "No" then
    return
end if



The script is available here https://github.com/b0gdanw/AppleScr...2896cb6dcc377480/SafariWebAppUninstaller.scpt
 
  • Like
Reactions: Slartibart
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.