概要
友人に「Mac にインストールされた同じバンドル ID のアプリケーションのフルパスを AppleScipt で取得する方法」を聞かれていたのを思い出してググったら、Terminal でできることがわかったので、メモとして残しておく。
Terminal で取得する方法
Terminal を起動してコマンド入力。
サンプルでは Adobe Illustrator のバンドル ID である「com.adobe.illustrator」を指定している。
コマンド
$ mdfind "kMDItemCFBundleIdentifier == 'com.adobe.illustrator'"
結果
/Applications/Adobe Illustrator CC 2015.3/Adobe Illustrator.app
/Applications/Adobe Illustrator CC 2017/Adobe Illustrator.app
AppleScript で取得する方法
do shell script を使いましょう。
sample
tell application "Finder"
set results to do shell script "mdfind \"kMDItemCFBundleIdentifier == 'com.adobe.illustrator'\""
log results
end tell
結果
(*/Applications/Adobe Illustrator CC 2015.3/Adobe Illustrator.app
/Applications/Adobe Illustrator CC 2017/Adobe Illustrator.app*)
そもそもバンドル ID がわからないという方は
- Application フォルダを開いて、任意のアプリケーションを選択して、コンテキストメニューを表示
- 「パッケージの内容を表示」を選択
- Contents フォルダの中にある Info.plist をテキストエディタなどで開く
- CFBundleIdentifier を検索して、下の行にある文字列がバンドル ID なので、それを使う
<key>CFBundleIdentifier</key>
<string>com.adobe.illustrator</string>