Macs in Chemistry

Insanely great science

 

An Applescript to Report installed and enabled extensions

When Apple released Safari version 5 one of the most important new features was the support for extensions. Extensions are a great way to add features to Safari to personalise web browsing, they enable the addition of features that you find useful. I have a listing of Extensions that might be useful for chemists. If you are working with them however it is a bit of a pain to check which are installed and which are enabled. This applescript from Christopher Stone is a very neat way of getting a report, it also serves as a demonstration of how to link to shell scripts, in particular using the unix command cat, a standard Unix utility that concatenates and lists files, to generate the report.

------------------------------------------------------------------------------------------------
#       Author: Christopher Stone
#      Contact: junksieve@thestoneforge.com
#      Created: 2012-05-03 : 10:42
#     Modified: 2012-05-04 : 05:30
#  Application: Safari
#      Purpose: Report installed and enabled extensions.
# Dependencies: none
------------------------------------------------------------------------------------------------
on fDate() # Example: 2010.11.12 » 04.06.58
  set formattedDate to do shell script "date \"+%Y.%m.%d » %H.%M.%S\""
    return formattedDate
end fDate
------------------------------------------------------------------------------------------------
on joinList(listToJoin, deLimiter)
  set {oldTIDS, AppleScript's text item delimiters} to {AppleScript's text item delimiters, deLimiter}
    set joinedList to listToJoin as string
    set AppleScript's text item delimiters to oldTIDS
    return joinedList
end joinList
------------------------------------------------------------------------------------------------
try
  
    set reportPath to "~/Desktop/\"Safari Extension Report " & fDate() & ".txt\""
    set safariExtensionsPlist to "~/Library/Safari/Extensions/Extensions.plist"
    set sep to "------------------------------------------------"

    tell application "System Events"
      tell property list file safariExtensionsPlist
          
            tell property list item "Installed Extensions"
              tell (property list items where name of its property list items contains "Enabled")
                  set enabledSafariExtansions to get value of property list item "Archive File Name"
              end tell
          end tell

            tell property list items of property list item "Installed Extensions"
              set installedSafariExtansions to get value of property list item "Archive File Name"
          end tell

      end tell
  end tell

    set enabledSafariExtansions to joinList(enabledSafariExtansions, linefeed)
    set enabledSafariExtansions to do shell script "sort <<< " & quoted form of enabledSafariExtansions without altering line endings
    set installedSafariExtansions to joinList(installedSafariExtansions, linefeed)
    set installedSafariExtansions to do shell script "sort <<< " & quoted form of installedSafariExtansions without altering line endings

    set reportText to      sep, ¬
        "SAFARI EXTENSIONS REPORT" & " » " & fDate(), ¬
        sep, ¬
        "ENABLED EXTENSIONS:", ¬
        sep, ¬
        enabledSafariExtansions, ¬
        sep, ¬
        "INSTALLED EXTENSIONS:", ¬
        sep, ¬
        installedSafariExtansions, ¬
        sep, ¬
        ""}
  
    set reportText to joinList(reportText, linefeed)
    do shell script "cat <<< " & (quoted form of reportText) & " > " & reportPath

    # Uncomment to open the report in TextEdit.
    do shell script "open -a TextEdit " & reportPath

on error eMsg number eNum
  set {c, s} to {return, "------------------------------------------"}
    set e to s & c & "Error: " & eMsg & c & s & c & "Error Number: " & eNum & c & s
    beep
    display dialog e
end try
------------------------------------------------------------------------------------------------

You can download the script from here Safari Extension Report.scpt