List the extensions installed in Safari for Mac OS X, and state whether each one is enabled

It's primarily a matter of parsing the output of defaults read ~/Library/Safari/Extensions/extensions and formatting it in a user-friendly way. The result actually answers both of your questions:

defaults read ~/Library/Safari/Extensions/extensions | awk '
/Bundle Directory/ {
    split($0, t, /\"/);
    sub(".safariextension", "", t[4]);
    sub("-1", "", t[4]);
    bundle=t[4]
    e="disabled"
}
/Enabled/ {
    e="enabled";
}
/Hidden Bars/ {
    print bundle, "...", e
}' | sort --ignore-case

Creating a shell script out of it is left as an exercise to the reader.

Please note that this will most probably stop to work if Apple decides to change the format of ~/Library/Safari/Extensions/extensions


For posterity, another simple starting point that originated from what was once a different question:

List of enabled extensions, unsorted

defaults read ~/Library/Safari/Extensions/extensions | grep -B 1 "Enabled = 1"

The result is quick, but dirty:

  • for each item found there are three lines, one should suffice
  • in the one line of interest, the leading "Bundle Directory Name" = " and trailing "; are unnecessary
  • some of the bundle directory names include -1 — this, too, is unnecessary.

For Safari in pre-release build 16A319 of macOS Sierra (Mac OS X 10.12)

defaults read ~/Library/Safari/Extensions/extensions | grep -B 5 "Enabled = 1"