Search code examples
applescript

Unable to find the application support folder for a specified application inside an Apple Script


I have an apple script that asks the user to select an application as a prompt. I would like to know how it could be possible to find the directory of the Application Support folder for this application per example, Spotify is ~/Library/Application Support/Spotify/

On my mac, but like is there a way inside apple script to find this directory for the specific app. It would really be appreciated, thanks!

Because I would like to then delete this folder using Apple Script


Solution

  • This should accomplish what you're looking to achieve. Be careful though because using System Events to delete... deletes the item permanently instead of sending it to the Trash

    property folderNames : missing value
    
    tell application "System Events"
        set appSupportFolder to application support folder
        set folderNames to name of folders of appSupportFolder
        set theChoice to my chooseFolderToDelete()
        delete folder theChoice of appSupportFolder
    end tell
    
    to chooseFolderToDelete()
        activate
        set theChoice to (choose from list folderNames with prompt ¬
            "Select an Application's Support folder to delete" OK button name ¬
            "Delete Folder" cancel button name "Cancel") as text
    end chooseFolderToDelete