Search code examples
bashmacosapplescriptmacos-sierrasafari-extension

Find a key in a plist and save its value in MacOS


So I need to create a script that will delete our Safari extension product.

The problem is that sometimes the File name is changing and I cant just delete all .EXTZ Files from the Extension Folder.

So I thought maybe to look inside the Extension.Plist and see in the "installed extension key my extension sub key with the installed file name (see screenshot) Then Delete the file With the exact name in the extension folder. I Couldn't figure out how to do it Can Someone help ?

If you guys a better idea how to remove the extension it'll be nice!

The Screenshot of the Plist file : screen


Solution

  • Applescript has built in support for reading plist files in "System Events". You can use it to pull out the Archive File Name.

    tell application "System Events"
      tell property list file "File Path to plist file here"
          set plistValue to value of property list item "Installed Extensions"
          set plistFirstItem to item 1 of plistValue
          set archiveFileName to |archive file name| of plistFirstItem
        return archiveFileName
      end tell
    end tell
    

    This should return the string in that property. You can then delete the file with that name in the extensions folder.