diff options
author | Zhiming Wang <zmwangx@gmail.com> | 2015-05-04 14:55:10 -0700 |
---|---|---|
committer | Zhiming Wang <zmwangx@gmail.com> | 2015-05-04 14:55:10 -0700 |
commit | 301679861a2440a10c9eac746cec86459f445ef9 (patch) | |
tree | 5aad22ead01cf0da226623f603f33867896c0fea /source/blog/2015-03-22-back-up-os-x-app-icons.md | |
parent | d0a07c64afba47bbe8bfb56ba9893296a73fc7db (diff) | |
download | my_new_personal_website-301679861a2440a10c9eac746cec86459f445ef9.tar.xz my_new_personal_website-301679861a2440a10c9eac746cec86459f445ef9.zip |
remove all Octopress stuff
Diffstat (limited to 'source/blog/2015-03-22-back-up-os-x-app-icons.md')
-rw-r--r-- | source/blog/2015-03-22-back-up-os-x-app-icons.md | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/source/blog/2015-03-22-back-up-os-x-app-icons.md b/source/blog/2015-03-22-back-up-os-x-app-icons.md new file mode 100644 index 00000000..7f9eec4b --- /dev/null +++ b/source/blog/2015-03-22-back-up-os-x-app-icons.md @@ -0,0 +1,46 @@ +--- +layout: post +title: "Back up OS X app icons" +date: 2015-03-22 16:58:50 -0700 +comments: true +categories: +--- +OS X application icons are valuable assets, and it's interesting to see how they evolve over time. This is especially the case when we upgraded to OS X 10.10 Yosemite, when Apple and many design-aware third party developers overhauled (mainly flattened) their icons. + +However, we lose all the old icons when we do a major OS upgrade. Technically they still live in Time Machine backups, but those are a pain to pull out. Therefore, I wrote a script just now to back up app icons of all applications living in `/Applications` (including those symlinked to `/Applications`, e.g., apps installed through `brew cask`) and its level-one subdirectories, and `/System/Library/CoreServices` (for `Finder.app` and such). Here's the script: + +```bash backup-app-icons +#!/usr/bin/env bash +function app_version +{ + # $1 is the path to the app + /usr/libexec/PlistBuddy -c "print CFBundleShortVersionString" "$1"/Contents/Info.plist 2>/dev/null || date +%Y%m%d +} + +function app_icon_path +{ + # $1 is the path to the app + filename=$(/usr/libexec/PlistBuddy -c "print CFBundleIconFile" "$1"/Contents/Info.plist 2>/dev/null) + [[ -n ${filename} ]] || return + filename=$(basename "${filename}" .icns) + echo "$1/Contents/Resources/${filename}.icns" +} + +function process_app +{ + # $1 is the path to the app + name=$(basename "$1" .app | tr -d ' ') + path=$(realpath -e "$1") || { echo "${RED}error: broken link '${path}'${RESET}" >&2; return 1; } + version=$(app_version "${path}") + icon_path=$(app_icon_path "${path}") + [[ -n ${icon_path} ]] || { echo "${YELLOW}warning: '$1' has no app icon${RESET}"; return 1; } + [[ -f ${icon_path} ]] || { echo "${RED}error: '${icon_path}' does not exist${RESET}" >&2; return 1; } + cp "${icon_path}" "${name}-${version}.icns" + echo "${name}-${version}.icns" +} + +find /Applications -maxdepth 2 -name '*.app' | while read app; do process_app "${app}"; done +find /System/Library/CoreServices -maxdepth 1 -name '*.app' | while read app; do process_app "${app}"; done +``` + +The script is also available as a [gist](https://gist.github.com/zmwangx/fad97e085045a21ebc1d). |