Skip to content

Instantly share code, notes, and snippets.

@villeodell
Last active April 7, 2022 13:46
Show Gist options
  • Save villeodell/bfdf02e987d3fe0ab1b514dd5a49d350 to your computer and use it in GitHub Desktop.
Save villeodell/bfdf02e987d3fe0ab1b514dd5a49d350 to your computer and use it in GitHub Desktop.
macOS command line: list applications by last opened date and output to csv

List macOS applications by date last opened

Make a list of your current applications along with the date you last used them.

  1. Get the relevant metadata attributes for Applications to mimic "Date last opened" in Finder using mdls
  2. Convert plist xml output to json using yq
  3. With jq
    • select just the most recent date if multiple dates
    • sort the results
    • ouput the app name and date to csv

From the terminal:

mdls -name _kMDItemPSIDPath -name kMDItemLastUsedDate -name _kMDItemContentChangeDate -plist - /Applications/* |
  yq e -p=xml -o=json |
  jq '[ .plist.array.dict[] | { app: .string | split("Applications/") | .[1], date: ( .date | if type=="array" then . else [.] end | max | split("T") | .[0] ) } ] | sort_by(.date) | reverse | .[] | [.date, .app] | @csv'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment