Obtenir le Chemin d'Application sur macOS
Apprenez à trouver et récupérer les chemins d'installation d'applications sur Mac à l'aide de scripts. Ceci est essentiel pour la gestion d'applications, le déploiement de scripts et la configuration de listes autorisées/bloquées.
Trouveur de Chemin d'App Basique
Trouvez le chemin d'une application en utilisant son identifiant de bundle :
#!/bin/bash
# Spécifier l'ID de bundle
BUNDLE_ID="com.apple.Safari"
# Trouver le chemin d'app avec mdfind
APP_PATH=$(mdfind "kMDItemCFBundleIdentifier=='${BUNDLE_ID}'")
if [[ -n "$APP_PATH" ]]; then
echo "Chemin d'application : $APP_PATH"
else
echo "Application non trouvée : $BUNDLE_ID"
fi
Découverte de Chemin Avancée
Script avec validation et méthodes de recherche multiples :
#!/bin/bash
# Fonction pour trouver le chemin d'app
find_app_path() {
local bundle_id="$1"
# Méthode 1 : Utiliser mdfind avec identifiant de bundle
local app_path=$(mdfind "kMDItemCFBundleIdentifier=='${bundle_id}'" | head -1)
if [[ -n "$app_path" && -d "$app_path" ]]; then
echo "$app_path"
return 0
fi
# Méthode 2 : Rechercher dans répertoires communs
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
}
# Exemple d'utilisation
BUNDLE_ID="${1:-com.apple.Safari}"
echo "Recherche de l'application : $BUNDLE_ID"
if APP_PATH=$(find_app_path "$BUNDLE_ID"); then
echo "Application trouvée à : $APP_PATH"
# Obtenir infos supplémentaires
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 "Nom d'application : ${APP_NAME:-Inconnu}"
echo "Version : ${APP_VERSION:-Inconnue}"
else
echo "Application non trouvée : $BUNDLE_ID"
exit 1
fi
Trouveur de Chemins Multiples
Trouvez les chemins de plusieurs applications à la fois :
#!/bin/bash
# Tableau d'IDs de bundle à rechercher
BUNDLE_IDS=(
"com.apple.Safari"
"com.apple.finder"
"com.apple.systempreferences"
"com.microsoft.Excel"
"com.adobe.Photoshop"
)
# Fonction pour trouver le chemin d'app
find_app_path() {
local bundle_id="$1"
mdfind "kMDItemCFBundleIdentifier=='${bundle_id}'" | head -1
}
echo "=== Rapport Chemins d'Applications ==="
echo "Généré : $(date)"
echo "Appareil : $(hostname)"
echo "======================================="
for bundle_id in "${BUNDLE_IDS[@]}"; do
echo "Recherche : $bundle_id"
app_path=$(find_app_path "$bundle_id")
if [[ -n "$app_path" && -d "$app_path" ]]; then
echo " ✓ Trouvée : $app_path"
# Obtenir version d'app si disponible
version=$(defaults read "$app_path/Contents/Info.plist" CFBundleShortVersionString 2>/dev/null)
if [[ -n "$version" ]]; then
echo " 📦 Version : $version"
fi
else
echo " ✗ Non trouvée"
fi
echo
done
Découverte d'ID de Bundle
Trouvez les IDs de bundle des applications installées :
#!/bin/bash
echo "=== IDs de Bundle Applications Installées ==="
# Rechercher dans répertoires d'applications communs
SEARCH_PATHS=(
"/Applications"
"/System/Applications"
"/Applications/Utilities"
)
for search_path in "${SEARCH_PATHS[@]}"; do
if [[ -d "$search_path" ]]; then
echo "Scan : $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
Utilisation avec Roundfleet
- Modifiez la variable
BUNDLE_IDavec votre application cible - Pour plusieurs apps, mettez à jour le tableau
BUNDLE_IDS - Déployez via l'exécution de script distant Roundfleet
- Consultez les résultats dans l'historique des actions
IDs de Bundle Communs
| Application | ID de Bundle |
|---|---|
| Safari | com.apple.Safari |
| Finder | com.apple.finder |
| Préférences Système | 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 |
Dépannage
Aucun résultat trouvé : Vérifiez que l'ID de bundle est correct et l'application installée
Plusieurs chemins retournés : Utilisez head -1 pour obtenir le premier résultat ou filtrez par emplacement spécifique
Permission refusée : Assurez-vous que le script a les permissions d'accès système de fichiers nécessaires
Note : Les IDs de bundle sont sensibles à la casse. Utilisez le format exact fourni par le développeur de l'application.