AppleScript名:指定バンドルIDのアプリケーションのアイコンへのパスを求める |
— Created 2017-02-14 by Takaaki Naganoya — 2017 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" use framework "AppKit" –http://piyocast.com/as/archives/4460 set iconList to {"com.barebones.bbedit", "com.barebones.textwrangler", "com.apple.Finder"} repeat with i in iconList set aPath to retIconPath(i) of me if aPath is not equal to false then display dialog "ICNS test" with title i with icon ((POSIX file aPath) as alias) buttons {"OK"} default button 1 end if end repeat –指定バンドルIDのアプリケーションのアイコンのフルパスを取得する on retIconPath(anID) set aRes to chkAppIsInstalled(anID) of me if aRes = false then return false set appPathPOSIX to (current application’s NSWorkspace’s sharedWorkspace()’s absolutePathForAppBundleWithIdentifier:anID) as string set anIconPath to getIconFilePath(appPathPOSIX) of me return anIconPath end retIconPath –指定バンドルIDのアプリケーションが存在しているかチェック on chkAppIsInstalled(aBundleID as string) set aRes to current application’s NSWorkspace’s sharedWorkspace()’s URLForApplicationWithBundleIdentifier:aBundleID set bRes to (aRes is not equal to missing value) return bRes end chkAppIsInstalled –指定ファイルのアイコンのファイルのパスを取得する on getIconFilePath(aPOSIXPath) set anURL to current application’s |NSURL|’s fileURLWithPath:aPOSIXPath set myBundle to current application’s NSBundle’s bundleWithURL:anURL set aBundleID to myBundle’s bundleIdentifier() as text set anIconFileName to (myBundle’s objectForInfoDictionaryKey:"CFBundleIconFile") as string if anIconFileName does not end with ".icns" then set anIconFileName to anIconFileName & ".icns" end if set ifonFileFullPath to aPOSIXPath & "/Contents/Resources/" & anIconFileName return ifonFileFullPath end getIconFilePath |
(Visited 41 times, 1 visits today)