Created
January 15, 2026 04:22
-
-
Save dir/db53b1bb80565cf2e3ef878238478947 to your computer and use it in GitHub Desktop.
macOS Bundle Identifier Helper Scripts
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
| #!/usr/bin/env bash | |
| # | |
| # bundle-identifier-to-path.sh - Get the path of an app by its bundle identifier | |
| # | |
| bundle_id="${1:-$(< /dev/stdin)}" | |
| [[ -z $bundle_id ]] && echo "Usage: ${0##*/} <bundle id>" && exit 1 | |
| # Try mdfind first (faster, uses Spotlight index) | |
| path=$(mdfind "kMDItemCFBundleIdentifier == '$bundle_id'" 2> /dev/null | head -1) | |
| # Try Swift next, if mdfind returns nothing & Swift is installed | |
| if [[ -z $path ]] && command -v swift > /dev/null 2>&1; then | |
| path=$(swift -e 'import AppKit; print(NSWorkspace.shared.urlForApplication(withBundleIdentifier: "'$bundle_id'")?.path ?? "")') | |
| fi | |
| # Try lsregister | |
| if [[ -z $path ]]; then | |
| lsregister='/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister' | |
| if [[ -x $lsregister ]]; then | |
| path=$( | |
| $lsregister -dump 2> /dev/null \ | |
| | grep -B 10 -m 1 "identifier:[[:space:]]*${1}[[:space:]]*$" \ | |
| | grep '^path:' \ | |
| | sed 's/path:\s*//; s/^[[:space:]]*//; s/ (0x[0-9a-f]*)$//' | |
| ) | |
| fi | |
| fi | |
| # Exit with code 1 if we still don't have a path | |
| [[ -z $path ]] && exit 1 | |
| # Replace `/System/Volumes/Preboot/Cryptexes/App/System/Applications/` with `/Applications/` | |
| path=${path//\/System\/Volumes\/Preboot\/Cryptexes\/App\/System\/Applications\//\/Applications\/} | |
| # Otherwise, print the path | |
| printf "%s" "$path" |
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
| #!/usr/bin/env bash | |
| # | |
| # path-to-bundle-identifier.sh - Get the bundle identifier of an app by its path | |
| # | |
| path="${1:-$(< /dev/stdin)}" | |
| [[ -z $path ]] && echo "Usage: ${0##*/} <path>" && exit 1 | |
| # Try mdls first (faster, uses Spotlight index) | |
| bundle_id=$(mdls -raw -name kMDItemCFBundleIdentifier "$path" 2> /dev/null) | |
| [[ $bundle_id == *"could not find"* ]] && bundle_id='' | |
| # Try reading the app's Info.plist directly | |
| [[ -z $bundle_id ]] && bundle_id=$(defaults read "$path/Contents/Info.plist" CFBundleIdentifier 2> /dev/null) | |
| # Exit with code 1 if we still don't have a bundle identifier | |
| [[ -z $bundle_id ]] && exit 1 | |
| # Otherwise, print the bundle identifier | |
| printf "%s" "$bundle_id" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment