« [NSTask]シェルコマンドの実行 | トップページ | [NSRunningApplication]起動中のアプリケーションの終了 »

[bundleIdentifier]UTIを取得する

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
#
#
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7

use AppleScript version "2.8"
use framework "Foundation"
use scripting additions

property refMe : a reference to current application
property refNSString : a reference to refMe's NSString
property refNSURL : a reference to refMe's NSURL

set objFileManager to refMe's NSFileManager's defaultManager()

#####デフォルトロケーション
set ocidDefaultLocation to (objFileManager's URLsForDirectory:(refMe's NSApplicationDirectory) inDomains:(refMe's NSUserDomainMask))
#####ailisにしておく
set aliasDefaultLocation to ocidDefaultLocation as alias
#####バンドル形式がターゲット
set listChooseFileUTI to {"com.apple.bundle"}
#####メッセージ
set strPromptText to "アプリケーションを選んでください" as text
####ダイアログ
set aliasFilePath to (choose file with prompt strPromptText default location (aliasDefaultLocation) of type listChooseFileUTI with invisibles without multiple selections allowed and showing package contents) as alias
####戻り値はエイリアス
set strFilePath to POSIX path of aliasFilePath
####パスにして
set ocidFilePath to refNSString's stringWithString:strFilePath
####バンドルとして定義
set ocidApplicationPath to refMe's NSBundle's bundleWithPath:ocidFilePath
####定義したバンドルからUTIを取得
set ocidUTI to ocidApplicationPath's bundleIdentifier()
set strUTI to ocidUTI as text
log strUTI
#####定義したバンドルから表示名を取得
set ocidAppName to ocidApplicationPath's objectForInfoDictionaryKey:"CFBundleDisplayName"
set strAppName to ocidAppName as text
log strAppName
return
####戻り値が空の場合はCFBundleExecutable名を取得する
if ocidAppName is (missing value) then
set ocidAppName to ocidApplicationPath's objectForInfoDictionaryKey:"CFBundleExecutable"
set strAppName to ocidAppName as text
end if

###表示用
set strDefaultAnser to (strUTI & "\n" & strAppName) as text
####アイコンパス
set aliasIconPath to POSIX file "/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/AlertNoteIcon.icns"
###ダイアログで戻す
display dialog "詳しく" with title "短め" default answer strDefaultAnser buttons {"OK", "キャンセル"} default button "OK" with icon aliasIconPath giving up after 15 without hidden answer

|

« [NSTask]シェルコマンドの実行 | トップページ | [NSRunningApplication]起動中のアプリケーションの終了 »

NSBundle」カテゴリの記事

UTType」カテゴリの記事