各種記法で記述したアプリケーション名から、Bundle IDを求めるAppleScriptです。
アプリケーション名(本当の名前)、Bundle ID、アプリケーションのフルパス(POSIX path)の3形式で記述したアプリケーション名から、Bundle IDを求めます。
ただし、Localized Name(Reminders–>「リマインダー」、Notes–>「メモ」)からBundle IDの取得は本Scriptではサポートしていません。
AppleScript名:アプリケーションの各種記法からBundle IDを求める |
use AppleScript version "2.5" use scripting additions use framework "Foundation" use framework "AppKit" set apList to {"Finder", "System Events", "com.apple.Finder", "/Applications/Safari"} set bIDList to retAppBundleID(apList) of me –> {"com.apple.finder", "com.apple.systemevents", "com.apple.Finder", "com.apple.Safari"} –Application name list –> Bundle ID list on retAppBundleID(appNameList) set resList to {} repeat with i in appNameList set j to contents of i if j starts with "/Applications/" then –POSIX path if j does not end with ".app" then set j to j & ".app" end if set aRes to getBundleIDFromPath(j) of me else if j contains "." then –Bundle ID (maybe) copy j to aRes else –Application Name set aRes to getBundleIDFromAppName(j) of me end if set the end of resList to aRes end repeat return resList end retAppBundleID –Application path –> Bundle ID on getBundleIDFromPath(aPOSIXpath) set aURL to current application’s |NSURL|’s fileURLWithPath:aPOSIXpath set aWorkspace to current application’s NSWorkspace’s sharedWorkspace() set appURL to aWorkspace’s URLForApplicationToOpenURL:aURL set aBundle to current application’s NSBundle’s bundleWithURL:appURL set anID to aBundle’s bundleIdentifier() return anID as string end getBundleIDFromPath –Application Name –> path –> Bundle ID on getBundleIDFromAppName(appName) try –Localized Name will require choose application dialog set appPath to POSIX path of (path to application appName) on error return "" end try return getBundleIDFromPath(appPath) of me end getBundleIDFromAppName |
More from my site
(Visited 54 times, 1 visits today)