Created
July 31, 2012 20:27
-
-
Save ttscoff/3220193 to your computer and use it in GitHub Desktop.
Retrieve Bundle Identifiers for OS X applications using semi-fuzzy string matching
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bid() { | |
local shortname location | |
# combine all args as regex | |
# (and remove ".app" from the end if it exists due to autocomplete) | |
shortname=$(echo "${@%%.app}"|sed 's/ /.*/g') | |
# if the file is a full match in apps folder, roll with it | |
if [ -d "/Applications/$shortname.app" ]; then | |
location="/Applications/$shortname.app" | |
else # otherwise, start searching | |
location=$(mdfind -onlyin /Applications -onlyin ~/Applications -onlyin /Developer/Applications 'kMDItemKind==Application'|awk -F '/' -v re="$shortname" 'tolower($NF) ~ re {print $0}'|head -n1) | |
fi | |
# No results? Die. | |
[[ -z $location || $location = "" ]] && echo "$1 not found, I quit" && return | |
# Otherwise, find the bundleid using spotlight metadata | |
bundleid=$(mdls -name kMDItemCFBundleIdentifier -r "$location") | |
# return the result or an error message | |
[[ -z $bundleid || $bundleid = "" ]] && echo "Error getting bundle ID for \"$@\"" || echo "$location: $bundleid" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment