Created
November 9, 2019 06:59
-
-
Save ttscoff/86fe788beb8c586986de179e6d6515c7 to your computer and use it in GitHub Desktop.
bid command for Fish
This file contains 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
# Defined in /Users/ttscoff/.config/fish/brett.fish @ line 240 | |
function bid --description 'Get bundle id for app name' | |
set -l shortname (echo "$argv"| sed -E 's/\.app$//'|sed 's/\\\//g') | |
set -l location | |
# if the file is a match in apps folder, don't spotlight | |
if test -d "/Applications/$shortname.localized/$shortname.app" | |
set location "/Applications/$shortname.localized/$shortname.app" | |
else if test -d "/Applications/$shortname.app" | |
set location "/Applications/$shortname.app" | |
else # use spotlight | |
set location (mdfind -onlyin /Applications -onlyin /Applications/Setapp -onlyin /Applications/Utilities -onlyin ~/Applications -onlyin /Developer/Applications "kMDItemKind==Application && kMDItemDisplayName=='*$shortname*'cdw"|head -n1) | |
end | |
# No result? Die. | |
if test -z $location | |
echo "$argv not found, I quit" | |
return | |
end | |
# Find the bundleid using spotlight metadata | |
set -l bundleid (mdls -name kMDItemCFBundleIdentifier -r "$location") | |
# return the result or an error message | |
if test -z $bundleid | |
echo "Error getting bundle ID for \"$argv\"" | |
else | |
echo "$location: $bundleid" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment