Get Application Path on macOS
Learn how to find and retrieve application installation paths on Mac devices using scripts. This is essential for application management, script deployment, and allowlist/blocklist configuration.
Basic App Path Finder
Find the path of an application using its bundle identifier:
#!/bin/bash
# Specify the bundle ID
BUNDLE_ID="com.apple.Safari"
# Find app path using mdfind
APP_PATH=$(mdfind "kMDItemCFBundleIdentifier=='${BUNDLE_ID}'")
if [[ -n "$APP_PATH" ]]; then
echo "Application path: $APP_PATH"
else
echo "Application not found: $BUNDLE_ID"
fi
Enhanced Path Discovery
Script with validation and multiple search methods:
#!/bin/bash
# Function to find app path
find_app_path() {
local bundle_id="$1"
# Method 1: Use mdfind with bundle identifier
local app_path=$(mdfind "kMDItemCFBundleIdentifier=='${bundle_id}'" | head -1)
if [[ -n "$app_path" && -d "$app_path" ]]; then
echo "$app_path"
return 0
fi
# Method 2: Search common directories
local common_paths=(
"/Applications"
"/System/Applications"
"/Applications/Utilities"
"/System/Library/CoreServices"
)
for path in "${common_paths[@]}"; do
if [[ -d "$path" ]]; then
local found=$(find "$path" -name "*.app" -maxdepth 2 -exec defaults read {}/Contents/Info.plist CFBundleIdentifier \; -print 2>/dev/null | grep -B1 "^${bundle_id}$" | grep "\.app$")
if [[ -n "$found" ]]; then
echo "$found"
return 0
fi
fi
done
return 1
}
# Example usage
BUNDLE_ID="${1:-com.apple.Safari}"
echo "Searching for application: $BUNDLE_ID"
if APP_PATH=$(find_app_path "$BUNDLE_ID"); then
echo "Found application at: $APP_PATH"
# Get additional info
APP_NAME=$(defaults read "$APP_PATH/Contents/Info.plist" CFBundleName 2>/dev/null)
APP_VERSION=$(defaults read "$APP_PATH/Contents/Info.plist" CFBundleShortVersionString 2>/dev/null)
echo "Application Name: ${APP_NAME:-Unknown}"
echo "Version: ${APP_VERSION:-Unknown}"
else
echo "Application not found: $BUNDLE_ID"
exit 1
fi
Multiple App Path Finder
Find paths for multiple applications at once:
#!/bin/bash
# Array of bundle IDs to search for
BUNDLE_IDS=(
"com.apple.Safari"
"com.apple.finder"
"com.apple.systempreferences"
"com.microsoft.Excel"
"com.adobe.Photoshop"
)
# Function to find app path
find_app_path() {
local bundle_id="$1"
mdfind "kMDItemCFBundleIdentifier=='${bundle_id}'" | head -1
}
echo "=== Application Path Report ==="
echo "Generated: $(date)"
echo "Device: $(hostname)"
echo "================================"
for bundle_id in "${BUNDLE_IDS[@]}"; do
echo "Searching: $bundle_id"
app_path=$(find_app_path "$bundle_id")
if [[ -n "$app_path" && -d "$app_path" ]]; then
echo " ✓ Found: $app_path"
# Get app version if available
version=$(defaults read "$app_path/Contents/Info.plist" CFBundleShortVersionString 2>/dev/null)
if [[ -n "$version" ]]; then
echo " 📦 Version: $version"
fi
else
echo " ✗ Not found"
fi
echo
done
Bundle ID Discovery
Find bundle IDs of installed applications:
#!/bin/bash
echo "=== Installed Applications Bundle IDs ==="
# Search in common application directories
SEARCH_PATHS=(
"/Applications"
"/System/Applications"
"/Applications/Utilities"
)
for search_path in "${SEARCH_PATHS[@]}"; do
if [[ -d "$search_path" ]]; then
echo "Scanning: $search_path"
find "$search_path" -name "*.app" -maxdepth 2 | while read app_path; do
app_name=$(basename "$app_path" .app)
bundle_id=$(defaults read "$app_path/Contents/Info.plist" CFBundleIdentifier 2>/dev/null)
if [[ -n "$bundle_id" ]]; then
echo " $app_name -> $bundle_id"
fi
done
echo
fi
done
Usage with MacFleet
- Modify the
BUNDLE_ID
variable with your target application - For multiple apps, update the
BUNDLE_IDS
array - Deploy through MacFleet's remote script execution
- View results in the action history
Common Bundle IDs
Application | Bundle ID |
---|---|
Safari | com.apple.Safari |
Finder | com.apple.finder |
System Preferences | com.apple.systempreferences |
Microsoft Word | com.microsoft.Word |
Google Chrome | com.google.Chrome |
Firefox | org.mozilla.firefox |
Slack | com.tinyspeck.slackmacgap |
Zoom | us.zoom.xos |
Troubleshooting
No results found: Verify the bundle ID is correct and application is installed
Multiple paths returned: Use head -1
to get the first result or filter by specific location
Permission denied: Ensure script has necessary file system access permissions
Note: Bundle IDs are case-sensitive. Use the exact format as provided by the application developer.