AppleScript UTType

getBundleDocumentTypes

対象アプリケーションがオープンする事が出来るUTIを取得します

ダウンロード - getbundledocumenttypes.zip


【スクリプトエディタで開く】|

#!/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 framework "UniformTypeIdentifiers"
use framework "AppKit"
use scripting additions
property refMe : a reference to current application
###初期化
set appFileManager to refMe's NSFileManager's defaultManager()
set appShardWorkspace to refMe's NSWorkspace's sharedWorkspace()
##############################
###デフォルトロケーション
set ocidApplicationDirPathArray to (appFileManager's URLsForDirectory:(refMe's NSApplicationDirectory) inDomains:(refMe's NSUserDomainMask))
set ocidApplicationDirPathURL to ocidApplicationDirPathArray's firstObject()
set aliasDefaultLocation to ocidApplicationDirPathURL's absoluteURL() as alias
##############################
#####ダイアログを前面に
tell current application
  set strName to name as text
end tell
####スクリプトメニューから実行したら
if strName is "osascript" then
  tell application "Finder" to activate
else
  tell current application to activate
end if
##############################
#####ファイルを選択
set listUTI to {"public.item"}
set strPromptText to "アプリケーションを選んで下さい。" as text
set strMesText to "アプリケーションを選んで下さい。" as text
set aliasFilePath to (choose file strMesText default location aliasDefaultLocation with prompt strPromptText of type listUTI with invisibles without multiple selections allowed and showing package contents) as alias
try
  set aliasFilePath to result as alias
on error
  log "エラーしました"
return "エラーしました"
end try
if aliasFilePath is false then
return "エラーしました"
end if
##############################
#####アプリケーションのパス
set strFilePath to POSIX path of aliasFilePath as text
set ocidFilePathStr to refMe's NSString's stringWithString:(strFilePath)
set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
set ocidFilePathURL to refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath) isDirectory:true
##PLISTのパス
set ocidPlistPathURL to ocidFilePathURL's URLByAppendingPathComponent:("Contents/Info.plist") isDirectory:false
##############################
#####CFBundleDocumentTypesの取得
set ocidPlistDict to refMe's NSMutableDictionary's alloc()'s initWithContentsOfURL:(ocidPlistPathURL)
set ocidDocTypeArray to ocidPlistDict's objectForKey:"CFBundleDocumentTypes"
if ocidDocTypeArray = (missing value) then
  set strOutPutText to "missing value" as text
else
  ####リストにする
  set listUTl to {} as list
  repeat with itemDocTypeArray in ocidDocTypeArray
    set listContentTypes to (itemDocTypeArray's objectForKey:"LSItemContentTypes")
    if listContentTypes = (missing value) then
      set ocidExtension to (itemDocTypeArray's objectForKey:"CFBundleTypeExtensions")
      set strClassName to ocidExtension's className() as text
      repeat with itemExtension in ocidExtension
set strExtension to itemExtension as text
set ocidContentTypes to (refMe's UTType's typeWithFilenameExtension:strExtension)
set strContentTypes to ocidContentTypes's identifier() as text
set strContentTypes to ("" & strContentTypes & "") as text
set end of listUTl to (strContentTypes)
      end repeat
    else
      repeat with itemContentTypes in listContentTypes
set strContentTypes to ("" & itemContentTypes & "") as text
set end of listUTl to (strContentTypes)
      end repeat
    end if
  end repeat
  ##############################
  set numCntUTI to (count of listUTl) as integer
  repeat with numCnt from 1 to numCntUTI
    if numCnt = 1 then
      set strOutPutText to ("{\"" & (item numCnt of listUTl as text) & "\",") as text
    else if numCnt = numCntUTI then
      set strOutPutText to strOutPutText & ("\"" & (item numCnt of listUTl as text) & "\"}") as text
    else
      set strOutPutText to strOutPutText & "\"" & (item numCnt of listUTl as text) & "\"," as text
    end if
  end repeat
end if
##set strText to listUTl as text
#####ダイアログに戻す
set aliasIconPath to POSIX file "/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/AlertNoteIcon.icns" as alias
###ダイアログ
set recordResult to (display dialog "type identifier 戻り値です" with title "uniform type identifier" default answer strOutPutText buttons {"クリップボードにコピー", "キャンセル", "OK"} default button "OK" giving up after 20 with icon aliasIconPath without hidden answer)
###クリップボードコピー
if button returned of recordResult is "クリップボードにコピー" then
  set strText to text returned of recordResult as text
  ####ペーストボード宣言
  set appPasteboard to refMe's NSPasteboard's generalPasteboard()
  set ocidText to (refMe's NSString's stringWithString:(strText))
appPasteboard's clearContents()
appPasteboard's setString:(ocidText) forType:(refMe's NSPasteboardTypeString)
end if



|

[CFBundleDocumentTypes]アプリケーションの対応DocumentTypesを取得する


【スクリプトエディタで開く】|

#!/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 framework "AppKIt"
use framework "UniformTypeIdentifiers"
use scripting additions
property refMe : a reference to current application
property strBundleID : "com.apple.QuickTimePlayerX"

set listUTI to doGetUTI()
log listUTI

to doGetUTI()
  ###アプリケーションのURLを取得
  ###NSバンドルをUTIから取得
  set ocidAppBundle to refMe's NSBundle's bundleWithIdentifier:(strBundleID)
  if ocidAppBundle = (missing value) then
    ###NSバンドル取得できなかった場合
    set appNSWorkspace to refMe's NSWorkspace's sharedWorkspace()
    set ocidAppPathURL to appNSWorkspace's URLForApplicationWithBundleIdentifier:(strBundleID)
  else
    set ocidAppPathURL to ocidAppBundle's bundleURL()
  end if
  ###Plistのパス
  set ocidPlistPathURL to ocidAppPathURL's URLByAppendingPathComponent:("Contents/Info.plist") isDirectory:false
  set ocidPlistDict to refMe's NSMutableDictionary's alloc()'s initWithContentsOfURL:(ocidPlistPathURL)
  set ocidDocTypeArray to ocidPlistDict's objectForKey:"CFBundleDocumentTypes"
  if ocidDocTypeArray = (missing value) then
    set strOutPutText to "missing value" as text
  else
    ####リストにする
    set listUTl to {} as list
    ###対応ドキュメントタイプをリストにしていく
    repeat with itemDocTypeArray in ocidDocTypeArray
      set listContentTypes to (itemDocTypeArray's objectForKey:"LSItemContentTypes")
      if listContentTypes = (missing value) then
###拡張子の指定のみの場合
set ocidExtension to (itemDocTypeArray's objectForKey:"CFBundleTypeExtensions")
set strClassName to ocidExtension's className() as text
repeat with itemExtension in ocidExtension
set strExtension to itemExtension as text
set ocidContentTypes to (refMe's UTType's typeWithFilenameExtension:(strExtension))
set strContentTypes to ocidContentTypes's identifier() as text
set strContentTypes to ("" & strContentTypes & "") as text
set end of listUTl to (strContentTypes)
end repeat
      else
repeat with itemContentTypes in listContentTypes
set strContentTypes to ("" & itemContentTypes & "") as text
set end of listUTl to (strContentTypes)
end repeat
      end if
    end repeat
  end if
return listUTl
end doGetUTI

|

[CFBundleDocumentTypes]アプリケーションの対応DocumentTypesを取得する


【スクリプトエディタで開く】|

#!/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 framework "UniformTypeIdentifiers"
use framework "AppKit"
use scripting additions
property refMe : a reference to current application
###初期化
set appFileManager to refMe's NSFileManager's defaultManager()
set appShardWorkspace to refMe's NSWorkspace's sharedWorkspace()
##############################
###デフォルトロケーション
set ocidApplicationDirPathArray to (appFileManager's URLsForDirectory:(refMe's NSApplicationDirectory) inDomains:(refMe's NSUserDomainMask))
set ocidApplicationDirPathURL to ocidApplicationDirPathArray's firstObject()
set aliasDefaultLocation to ocidApplicationDirPathURL's absoluteURL() as alias
##############################
#####ダイアログを前面に
tell current application
  set strName to name as text
end tell
####スクリプトメニューから実行したら
if strName is "osascript" then
  tell application "Finder" to activate
else
  tell current application to activate
end if
##############################
#####ファイルを選択
set listUTI to {"public.item"}
set strPromptText to "アプリケーションを選んで下さい。" as text
set strMesText to "アプリケーションを選んで下さい。" as text
set aliasFilePath to (choose file strMesText default location aliasDefaultLocation with prompt strPromptText of type listUTI with invisibles without multiple selections allowed and showing package contents) as alias
try
  set aliasFilePath to result as alias
on error
  log "エラーしました"
return "エラーしました"
end try
if aliasFilePath is false then
return "エラーしました"
end if
##############################
#####アプリケーションのパス
set strFilePath to POSIX path of aliasFilePath as text
set ocidFilePathStr to refMe's NSString's stringWithString:(strFilePath)
set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
set ocidFilePathURL to refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath) isDirectory:true
set ocidPlistPathURL to ocidFilePathURL's URLByAppendingPathComponent:("Contents/Info.plist") isDirectory:false
##############################
#####CFBundleDocumentTypesの取得
set ocidPlistDict to refMe's NSMutableDictionary's alloc()'s initWithContentsOfURL:(ocidPlistPathURL)
set ocidDocTypeArray to ocidPlistDict's objectForKey:"CFBundleDocumentTypes"
if ocidDocTypeArray = (missing value) then
  set strOutPutText to "missing value" as text
else
  ####リストにする
  set listUTl to {} as list
  repeat with itemDocTypeArray in ocidDocTypeArray
    set listContentTypes to (itemDocTypeArray's objectForKey:"LSItemContentTypes")
    if listContentTypes = (missing value) then
      set ocidExtension to (itemDocTypeArray's objectForKey:"CFBundleTypeExtensions")
      set strClassName to ocidExtension's className() as text
      repeat with itemExtension in ocidExtension
set strExtension to itemExtension as text
set ocidContentTypes to (refMe's UTType's typeWithFilenameExtension:strExtension)
set strContentTypes to ocidContentTypes's identifier() as text
set strContentTypes to ("" & strContentTypes & "") as text
set end of listUTl to (strContentTypes)
      end repeat
    else
      repeat with itemContentTypes in listContentTypes
set strContentTypes to ("" & itemContentTypes & "") as text
set end of listUTl to (strContentTypes)
      end repeat
    end if
  end repeat
  ##############################
  set numCntUTI to (count of listUTl) as integer
  repeat with numCnt from 1 to numCntUTI
    if numCnt = 1 then
      set strOutPutText to ("{\"" & (item numCnt of listUTl as text) & "\",") as text
    else if numCnt = numCntUTI then
      set strOutPutText to strOutPutText & ("\"" & (item numCnt of listUTl as text) & "\"}") as text
    else
      set strOutPutText to strOutPutText & "\"" & (item numCnt of listUTl as text) & "\"," as text
    end if
  end repeat
end if
##set strText to listUTl as text
#####ダイアログに戻す
set aliasIconPath to POSIX file "/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/AlertNoteIcon.icns" as alias
###ダイアログ
set recordResult to (display dialog "type identifier 戻り値です" with title "uniform type identifier" default answer strOutPutText buttons {"クリップボードにコピー", "キャンセル", "OK"} default button "OK" giving up after 20 with icon aliasIconPath without hidden answer)
###クリップボードコピー
if button returned of recordResult is "クリップボードにコピー" then
  set strText to text returned of recordResult as text
  ####ペーストボード宣言
  set appPasteboard to refMe's NSPasteboard's generalPasteboard()
  set ocidText to (refMe's NSString's stringWithString:(strText))
appPasteboard's clearContents()
appPasteboard's setString:(ocidText) forType:(refMe's NSPasteboardTypeString)
end if



|

[UTType]拡張子から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 framework "UniformTypeIdentifiers"
use scripting additions
property refMe : a reference to current application

log (refMe's UTType's typeWithFilenameExtension:"PDF")'s identifier() as text
-->(*com.adobe.pdf*)

|

[NSURLContentTypeKey]ファイルの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 framework "UniformTypeIdentifiers"
use framework "AppKit"
use scripting additions
property refMe : a reference to current application
###初期化
set appFileManager to refMe's NSFileManager's defaultManager()
set appShardWorkspace to refMe's NSWorkspace's sharedWorkspace()
##############################
###デフォルトロケーション
set ocidUserDesktopPathArray to (appFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask))
set ocidUserDesktopPathURL to ocidUserDesktopPathArray's firstObject()
set aliasUserDesktopPath to ocidUserDesktopPathURL's absoluteURL() as alias
##############################
#####ダイアログを前面に
tell current application
  set strName to name as text
end tell
####スクリプトメニューから実行したら
if strName is "osascript" then
  tell application "Finder" to activate
else
  tell current application to activate
end if
#####ファイルを選択
set listUTI to {"public.item"}
set strPromptText to "ファイルを選んで下さい。" as text
set strMesText to "UTIを取得します" as text

set aliasFilePath to (choose file strMesText default location aliasUserDesktopPath with prompt strPromptText of type listUTI with invisibles and showing package contents without multiple selections allowed) as alias


try
  set aliasFilePath to result as alias
on error
  log "エラーしました"
return "エラーしました"
end try
if aliasFilePath is false then
return "エラーしました"
end if
##############################
#####パス
set strFilePath to (POSIX path of aliasFilePath) as text
set ocidFilePathStr to (refMe's NSString's stringWithString:(strFilePath))
set ocidFilePath to ocidFilePathStr's stringByStandardizingPath
set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath) isDirectory:true)
####UTIの取得
set listResourceValue to (ocidFilePathURL's getResourceValue:(reference) forKey:(refMe's NSURLContentTypeKey) |error|:(reference))
set ocidContentType to (item 2 of listResourceValue)
set strUTI to (ocidContentType's identifier) as text
log strUTI
###missing value対策
if strUTI is "" then
  tell application "Finder"
    set objInfo to info for aliasFilePath
    set strUTI to type identifier of objInfo as text
  end tell
  log strUTI
end if

##############################
#####UTIからデフォルトアプリケーションのアイコンパスを求める
set listResourceValue to (ocidFilePathURL's getResourceValue:(reference) forKey:(refMe's NSURLContentTypeKey) |error|:(reference))
set ocidUTType to (item 2 of listResourceValue)
###選択したファイルのデフォルトのアプリケーションを取得
set ocidAppPathURL to appShardWorkspace's URLForApplicationToOpenContentType:(ocidUTType)
###デフォルトのアプリケーションが見つからない場合はファインダーにする
if ocidAppPathURL = (missing value) then
  set strFinderPath to "/System/Library/CoreServices/Finder.app"
  set ocidFinderPathStr to (refMe's NSString's stringWithString:(strFinderPath))
  set ocidFinderPath to ocidFinderPathStr's stringByStandardizingPath()
  set ocidAppPathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFinderPath) isDirectory:false)
else
  log ocidAppPathURL's absoluteString() as text
end if
###アイコン名をPLISTから取得
set ocidPlistPathURL to ocidAppPathURL's URLByAppendingPathComponent:("Contents/Info.plist") isDirectory:false
set ocidPlistDict to refMe's NSMutableDictionary's alloc()'s initWithContentsOfURL:(ocidPlistPathURL)
set strIconFileName to (ocidPlistDict's valueForKey:("CFBundleIconFile")) as text
###ICONのURLにして
set strPath to ("Contents/Resources/" & strIconFileName) as text
set ocidIconFilePathURL to ocidAppPathURL's URLByAppendingPathComponent:(strPath) isDirectory:false
###拡張子の有無チェック
set strExtensionName to (ocidIconFilePathURL's pathExtension()) as text
if strExtensionName is "" then
  set ocidIconFilePathURL to ocidIconFilePathURL's URLByAppendingPathExtension:"icns"
end if
##-->これがアイコンパス
log ocidIconFilePathURL's absoluteString() as text
###ICONファイルが実際にあるか?チェック
set boolExists to appFileManager's fileExistsAtPath:(ocidIconFilePathURL's |path|)
###ICONがみつかない時用にデフォルトを用意する
if boolExists is false then
  set aliasIconPath to POSIX file "/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/AlertNoteIcon.icns"
else
  set aliasIconPath to ocidIconFilePathURL's absoluteURL() as alias
end if

###ダイアログ
set recordResult to (display dialog "type identifier 戻り値です" with title "uniform type identifier" default answer strUTI buttons {"クリップボードにコピー", "キャンセル", "OK"} default button "OK" giving up after 20 with icon aliasIconPath without hidden answer)
###クリップボードコピー
if button returned of recordResult is "クリップボードにコピー" then
  set strText to text returned of recordResult as text
  ####ペーストボード宣言
  set appPasteboard to refMe's NSPasteboard's generalPasteboard()
  set ocidText to (refMe's NSString's stringWithString:(strText))
appPasteboard's clearContents()
appPasteboard's setString:(ocidText) forType:(refMe's NSPasteboardTypeString)
end if



|

ファイルのuniform type identifierを求める


【スクリプトエディタで開く】|

#!/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 framework "UniformTypeIdentifiers"
use framework "AppKit"
use scripting additions
property refMe : a reference to current application
###初期化
set appFileManager to refMe's NSFileManager's defaultManager()
set appShardWorkspace to refMe's NSWorkspace's sharedWorkspace()
##############################
###デフォルトロケーション
set ocidUserDesktopPathArray to (appFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask))
set ocidUserDesktopPathURL to ocidUserDesktopPathArray's firstObject()
set aliasUserDesktopPath to ocidUserDesktopPathURL's absoluteURL() as alias
##############################
#####ダイアログを前面に
tell current application
  set strName to name as text
end tell
####スクリプトメニューから実行したら
if strName is "osascript" then
  tell application "Finder" to activate
else
  tell current application to activate
end if
#####ファイルを選択
set listUTI to {"public.item"}
set strPromptText to "ファイルを選んで下さい。" as text
set strMesText to "UTIを取得します" as text
set aliasFilePath to (choose file strMesText default location aliasUserDesktopPath with prompt strPromptText of type listUTI with invisibles and showing package contents without multiple selections allowed) as alias
try
  set aliasFilePath to result as alias
on error
  log "エラーしました"
return "エラーしました"
end try
if aliasFilePath is false then
return "エラーしました"
end if
##############################
#####パス
set strFilePath to (POSIX path of aliasFilePath) as text
set ocidFilePathStr to (refMe's NSString's stringWithString:(strFilePath))
set ocidFilePath to ocidFilePathStr's stringByStandardizingPath
set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath) isDirectory:true)
####UTIの取得
set listResourceValue to (ocidFilePathURL's getResourceValue:(reference) forKey:(refMe's NSURLContentTypeKey) |error|:(reference))
set ocidContentType to (item 2 of listResourceValue)
set strUTI to (ocidContentType's identifier) as text
###missing value対策
if strUTI is "" then
  tell application "Finder"
    set objInfo to info for aliasFilePath
    set strUTI to type identifier of objInfo as text
  end tell
end if

##############################
#####UTIからデフォルトアプリケーションのアイコンパスを求める
set listResourceValue to (ocidFilePathURL's getResourceValue:(reference) forKey:(refMe's NSURLContentTypeKey) |error|:(reference))
set ocidUTType to (item 2 of listResourceValue)
###選択したファイルのデフォルトのアプリケーションを取得
set ocidAppPathURL to appShardWorkspace's URLForApplicationToOpenContentType:(ocidUTType)
log ocidAppPathURL's absoluteString() as text
###アイコン名をPLISTから取得
set ocidPlistPathURL to ocidAppPathURL's URLByAppendingPathComponent:("Contents/Info.plist") isDirectory:false
set ocidPlistDict to refMe's NSMutableDictionary's alloc()'s initWithContentsOfURL:(ocidPlistPathURL)
set strIconFileName to (ocidPlistDict's valueForKey:("CFBundleIconFile")) as text
###ICONのURLにして
set strPath to ("Contents/Resources/" & strIconFileName) as text
set ocidIconFilePathURL to ocidAppPathURL's URLByAppendingPathComponent:(strPath) isDirectory:false
###拡張子の有無チェック
set strExtensionName to (ocidIconFilePathURL's pathExtension()) as text
if strExtensionName is "" then
  set ocidIconFilePathURL to ocidIconFilePathURL's URLByAppendingPathExtension:"icns"
end if
##-->これがアイコンパス
log ocidIconFilePathURL's absoluteString() as text
###ICONファイルが実際にあるか?チェック
set boolExists to appFileManager's fileExistsAtPath:(ocidIconFilePathURL's |path|)
###ICONがみつかない時用にデフォルトを用意する
if boolExists is false then
  set aliasIconPath to POSIX file "/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/AlertNoteIcon.icns"
else
  set aliasIconPath to ocidIconFilePathURL's absoluteURL() as alias
end if

###ダイアログ
set recordResult to (display dialog "type identifier 戻り値です" with title "uniform type identifier" default answer strUTI buttons {"クリップボードにコピー", "キャンセル", "OK"} default button "OK" giving up after 20 with icon aliasIconPath without hidden answer)
###クリップボードコピー
if button returned of recordResult is "クリップボードにコピー" then
  set strText to text returned of recordResult as text
  ####ペーストボード宣言
  set appPasteboard to refMe's NSPasteboard's generalPasteboard()
  set ocidText to (refMe's NSString's stringWithString:(strText))
appPasteboard's clearContents()
appPasteboard's setString:(ocidText) forType:(refMe's NSPasteboardTypeString)
end if



com.apple.application-bundleもとれるタイプ

【スクリプトエディタで開く】|

#!/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 framework "UniformTypeIdentifiers"
use framework "AppKit"
use scripting additions
property refMe : a reference to current application
###初期化
set appFileManager to refMe's NSFileManager's defaultManager()
set appShardWorkspace to refMe's NSWorkspace's sharedWorkspace()
##############################
###デフォルトロケーション
set ocidUserDesktopPathArray to (appFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask))
set ocidUserDesktopPathURL to ocidUserDesktopPathArray's firstObject()
set aliasUserDesktopPath to ocidUserDesktopPathURL's absoluteURL() as alias
##############################
#####ダイアログを前面に
tell current application
  set strName to name as text
end tell
####スクリプトメニューから実行したら
if strName is "osascript" then
  tell application "Finder" to activate
else
  tell current application to activate
end if
#####ファイルを選択
set listUTI to {"public.item"}
set strPromptText to "ファイルを選んで下さい。" as text
set strMesText to "UTIを取得します" as text

set aliasFilePath to (choose file strMesText default location aliasUserDesktopPath with prompt strPromptText of type listUTI with invisibles without showing package contents and multiple selections allowed) as alias


try
  set aliasFilePath to result as alias
on error
  log "エラーしました"
return "エラーしました"
end try
if aliasFilePath is false then
return "エラーしました"
end if
##############################
#####パス
set strFilePath to (POSIX path of aliasFilePath) as text
set ocidFilePathStr to (refMe's NSString's stringWithString:(strFilePath))
set ocidFilePath to ocidFilePathStr's stringByStandardizingPath
set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath) isDirectory:true)
####UTIの取得
set listResourceValue to (ocidFilePathURL's getResourceValue:(reference) forKey:(refMe's NSURLContentTypeKey) |error|:(reference))
set ocidContentType to (item 2 of listResourceValue)
set strUTI to (ocidContentType's identifier) as text
###missing value対策
if strUTI is "" then
  tell application "Finder"
    set objInfo to info for aliasFilePath
    set strUTI to type identifier of objInfo as text
  end tell
end if

##############################
#####UTIからデフォルトアプリケーションのアイコンパスを求める
set listResourceValue to (ocidFilePathURL's getResourceValue:(reference) forKey:(refMe's NSURLContentTypeKey) |error|:(reference))
set ocidUTType to (item 2 of listResourceValue)
###選択したファイルのデフォルトのアプリケーションを取得
set ocidAppPathURL to appShardWorkspace's URLForApplicationToOpenContentType:(ocidUTType)
if ocidAppPathURL = (missing value) then
  set boolExists to false
else
  
  log ocidAppPathURL's absoluteString() as text
  ###アイコン名をPLISTから取得
  set ocidPlistPathURL to ocidAppPathURL's URLByAppendingPathComponent:("Contents/Info.plist") isDirectory:false
  set ocidPlistDict to refMe's NSMutableDictionary's alloc()'s initWithContentsOfURL:(ocidPlistPathURL)
  set strIconFileName to (ocidPlistDict's valueForKey:("CFBundleIconFile")) as text
  ###ICONのURLにして
  set strPath to ("Contents/Resources/" & strIconFileName) as text
  set ocidIconFilePathURL to ocidAppPathURL's URLByAppendingPathComponent:(strPath) isDirectory:false
  ###拡張子の有無チェック
  set strExtensionName to (ocidIconFilePathURL's pathExtension()) as text
  if strExtensionName is "" then
    set ocidIconFilePathURL to ocidIconFilePathURL's URLByAppendingPathExtension:"icns"
  end if
  ##-->これがアイコンパス
  log ocidIconFilePathURL's absoluteString() as text
  ###ICONファイルが実際にあるか?チェック
  set boolExists to appFileManager's fileExistsAtPath:(ocidIconFilePathURL's |path|)
end if
###ICONがみつかない時用にデフォルトを用意する
if boolExists is false then
  set aliasIconPath to POSIX file "/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/AlertNoteIcon.icns"
else
  set aliasIconPath to ocidIconFilePathURL's absoluteURL() as alias
end if

###ダイアログ
set recordResult to (display dialog "type identifier 戻り値です" with title "uniform type identifier" default answer strUTI buttons {"クリップボードにコピー", "キャンセル", "OK"} default button "OK" giving up after 20 with icon aliasIconPath without hidden answer)
###クリップボードコピー
if button returned of recordResult is "クリップボードにコピー" then
  set strText to text returned of recordResult as text
  ####ペーストボード宣言
  set appPasteboard to refMe's NSPasteboard's generalPasteboard()
  set ocidText to (refMe's NSString's stringWithString:(strText))
appPasteboard's clearContents()
appPasteboard's setString:(ocidText) forType:(refMe's NSPasteboardTypeString)
end if



|

MIME-TYPEを取得する(ローカルファイル)


【スクリプトエディタで開く】|

#!/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 framework "UniformTypeIdentifiers"
use framework "AppKit"
use scripting additions

property refMe : a reference to current application

##############################
###デフォルトロケーション
set appFileManager to refMe's NSFileManager's defaultManager()
set ocidUserDesktopPathArray to (appFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask))
set ocidUserDesktopPathURL to ocidUserDesktopPathArray's firstObject()
set aliasUserDesktopPath to ocidUserDesktopPathURL's absoluteURL() as alias
##############################
#####ダイアログを前面に
tell current application
  set strName to name as text
end tell
####スクリプトメニューから実行したら
if strName is "osascript" then
  tell application "Finder" to activate
else
  tell current application to activate
end if
#####ファイルを選択
set listUTI to {"public.item"}
set strPromptText to "ファイルを選んで下さい。" as text
set strMesText to "MIME-TYPEを取得します" as text
set aliasFilePath to (choose file strMesText default location aliasUserDesktopPath with prompt strPromptText of type listUTI with invisibles without multiple selections allowed) as alias

######ファイルURL
set strFilePath to POSIX path of aliasFilePath
set ocidFilePathStr to (refMe's NSString's stringWithString:(strFilePath))
set ocidFilePath to ocidFilePathStr's stringByStandardizingPath
set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath) isDirectory:false)

####UTIの取得
set listResponse to (ocidFilePathURL's getResourceValue:(reference) forKey:(refMe's NSURLContentTypeKey) |error|:(reference))
set ocidContentType to (item 2 of listResponse)
set ocidTagDict to (ocidContentType's tags)

log ocidTagDict as record
##MIME-TYPEの取得
set ocidMimeType to ocidTagDict's valueForKey:"public.mime-type"
###tagにmimeが含まれていなかったら
if ocidMimeType = (missing value) then
  set theCommandText to ("/usr/bin/file --mime-type \"" & strFilePath & "\" | cut -f 2 -d ':'") as text
  log theCommandText
  set strMimeType to (do shell script theCommandText) as text
else
  ###tagにmimeがあればそのまま値を利用する
  set strMimeType to (ocidContentType's preferredMIMEType()) as text
end if

###ダイアログ
set strIconPath to "/System/Library/CoreServices/Finder.app/Contents/Resources/Finder.icns"
set aliasIconPath to POSIX file strIconPath as alias
set recordResult to (display dialog "MiMETypeの戻り値です" with title "MiMEType" default answer strMimeType buttons {"クリップボードにコピー", "キャンセル", "OK"} default button "OK" giving up after 20 with icon aliasIconPath without hidden answer)

if button returned of recordResult is "クリップボードにコピー" then
  set strText to text returned of recordResult as text
  ####ペーストボード宣言
  set appPasteboard to refMe's NSPasteboard's generalPasteboard()
  set ocidText to (refMe's NSString's stringWithString:(strText))
appPasteboard's clearContents()
appPasteboard's setString:(ocidText) forType:(refMe's NSPasteboardTypeString)
end if


|

UTType 基本


【スクリプトエディタで開く】|

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
(*
error number -128
com.cocolog-nifty.quicktimer.icefloe
*)
#
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
##自分環境がos12なので2.8にしているだけです
use AppleScript version "2.8"
use framework "Foundation"
use framework "AppKit"
use scripting additions

property refMe : a reference to current application

###拡張子から
set ocidUTType to refMe's UTType's typeWithFilenameExtension:"html"
log className() of ocidUTType as text
-->(*_UTCoreType*)

###UTIから
set ocidUTType to refMe's UTType's typeWithIdentifier:"public.html"
log className() of ocidUTType as text
-->(*_UTCoreType*)

###MIMEから
set ocidUTType to refMe's UTType's typeWithMIMEType:"text/html"
log className() of ocidUTType as text
-->(*_UTCoreType*)

log ocidUTType's identifier() as text
-->(*public.html*)

log ocidUTType's preferredFilenameExtension() as text
-->(*html*)

log ocidUTType's preferredMIMEType() as text
-->(*text/html*)


|

[NSURLContentTypeKey]NSURLの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
set appFileManager to refMe's NSFileManager's defaultManager()

set strFilePath to "/System/Library/Fonts/Avenir Next.ttc"
set ocidFilePathStr to refMe's NSString's stringWithString:(strFilePath)
set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath) isDirectory:false)

set listResult to (ocidFilePathURL's getResourceValue:(reference) forKey:(refMe's NSURLContentTypeKey) |error|:(reference))

if (item 1 of listResult) is false then
return "取得に失敗しました"
else
  set ocidContentType to (item 2 of listResult)
  log className() of ocidContentType as text
  -->(*UTType*)
  set strUTI to (ocidContentType's identifier) as text
  -->"public.truetype-collection-font"
  log (ocidContentType's preferredFilenameExtension) as text
  --> ttc
end if


|

[UTI] UTIを求める(type identifier of info for)


【スクリプトエディタで開く】|

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
(* ツールバーにある右三角▶︎をクリックしてください↑
com.cocolog-nifty.quicktimer.icefloe
*)
#
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
##自分環境がos12なので2.8にしているだけです
use AppleScript version "2.8"
use framework "Foundation"
use scripting additions

set filepath to "/System/Library/ProductDocuments/ProductGuides/ENERGY STAR.pdf"

set aliasFilePath to POSIX file filepath as alias

log file type of (info for aliasFilePath)
log file creator of (info for aliasFilePath)
log kind of (info for aliasFilePath)

set strUTI to (type identifier of (info for aliasFilePath)) as text
-->"com.adobe.pdf"

|

その他のカテゴリー

Acrobat Acrobat Annotation Acrobat Dialog Acrobat Form Acrobat JS Acrobat Open Acrobat Plugin Acrobat python Acrobat Reader Acrobat Sequ Acrobat Stamps Admin Admin Account Admin Apachectl Admin configCode Admin Device Management Admin LaunchServices Admin Locationd Admin loginitem Admin Maintenance Admin Permission Admin Pkg Admin Power Management Admin Printer Admin SetUp Admin SMB Admin System Information Admin Tools Admin Users Admin Volumes Adobe Apple AppleScript AppleScript Guide AppleScript Accessibility AppleScript AppKit AppleScript Applications AppleScript AppStore AppleScript Archive AppleScript Attributes AppleScript Automator AppleScript AVAsset AppleScript AVconvert AppleScript AVFoundation AppleScript AVURLAsset AppleScript BackUp AppleScript Barcode AppleScript Bash AppleScript Basic AppleScript Basic Path AppleScript Bluetooth AppleScript BOX AppleScript Browser AppleScript Calendar AppleScript CD/DVD AppleScript Choose AppleScript Chrome AppleScript CIImage AppleScript CloudStorage AppleScript Color AppleScript com.apple.LaunchServices.OpenWith AppleScript Console AppleScript Contacts AppleScript CotEditor AppleScript CURL AppleScript current application AppleScript Date&Time AppleScript delimiters AppleScript Desktop AppleScript Device AppleScript Disk AppleScript do shell script AppleScript Dock AppleScript DropBox AppleScript eMail AppleScript Encode Decode AppleScript Error AppleScript EXIFData AppleScript ffmpeg AppleScript File AppleScript Finder AppleScript Firefox AppleScript Folder AppleScript Fonts AppleScript GIF AppleScript HTML AppleScript Icon AppleScript Illustrator AppleScript Image Events AppleScript Image2PDF AppleScript ImageOptim Applescript iWork AppleScript Javascript AppleScript Jedit AppleScript Json AppleScript Label AppleScript List AppleScript locationd AppleScript LRC AppleScript LSSharedFileList AppleScript m3u8 AppleScript MakePDF AppleScript Map AppleScript Math AppleScript Microsoft AppleScript Microsoft Edge AppleScript Microsoft Excel AppleScript Mobileconfig AppleScript Mouse AppleScript Movie AppleScript Music AppleScript NetWork AppleScript Notes AppleScript NSArray AppleScript NSBitmapImageRep AppleScript NSBundle AppleScript NSCFBoolean AppleScript NSCharacterSet AppleScript NSColor AppleScript NSColorList AppleScript NSData AppleScript NSDictionary AppleScript NSError AppleScript NSEvent AppleScript NSFileAttributes AppleScript NSFileManager AppleScript NSFont AppleScript NSFontManager AppleScript NSImage AppleScript NSIndex AppleScript NSKeyedArchiver AppleScript NSKeyedUnarchiver AppleScript NSLocale AppleScript NSMutableArray AppleScript NSMutableDictionary AppleScript NSMutableString AppleScript NSNotFound AppleScript NSNumber AppleScript NSOpenPanel AppleScript NSPasteboard AppleScript NSPDFImageRep AppleScript NSpoint AppleScript NSPredicate AppleScript NSRange AppleScript NSRegularExpression AppleScript NSRunningApplication AppleScript NSScreen AppleScript NSSize AppleScript NSString AppleScript NSStringCompareOptions AppleScript NSTask AppleScript NSTimeZone AppleScript NSURL AppleScript NSURL File AppleScript NSURLBookmark AppleScript NSURLComponents AppleScript NSURLResourceKey AppleScript NSUserDefaults AppleScript NSUUID AppleScript NSView AppleScript NSWorkspace AppleScript Numbers AppleScript OAuth AppleScript ObjC AppleScript OneDrive AppleScript Osax AppleScript PDF AppleScript PDFAnnotationWidget AppleScript PDFContext AppleScript PDFDisplayBox AppleScript PDFDocumentPermissions AppleScript PDFKit AppleScript PDFnUP AppleScript PDFOutline AppleScript Photos AppleScript Photoshop AppleScript Plist System Events AppleScript PostScript AppleScript prefPane AppleScript Preview AppleScript Python AppleScript QR AppleScript QR Decode AppleScript QuickLook AppleScript QuickTime AppleScript record AppleScript Regular Expression AppleScript Reminders AppleScript ReName AppleScript Repeat AppleScript RTF AppleScript Safari AppleScript SaveFile AppleScript ScreenCapture AppleScript ScreenSaver AppleScript Script Editor AppleScript Script Menu AppleScript Shortcuts AppleScript Shortcuts Events AppleScript Sort AppleScript Sound AppleScript Spotlight AppleScript SRT AppleScript StandardAdditions AppleScript stringByApplyingTransform AppleScript System Events AppleScript System Settings AppleScript TemporaryItems AppleScript Terminal AppleScript Text AppleScript Text CSV AppleScript Text TSV AppleScript TextEdit AppleScript Translate AppleScript Trash AppleScript Twitter AppleScript UI AppleScript Unit Conversion AppleScript UTType AppleScript valueForKeyPath AppleScript Video AppleScript VisionKit AppleScript Visual Studio Code AppleScript webarchive AppleScript webp AppleScript Wifi AppleScript XML AppleScript XML EPUB AppleScript XML OPML AppleScript XML Plist AppleScript XML RSS AppleScript XML SVG AppleScript XML TTML AppleScript XML webloc AppleScript YouTube AppleScript Zero Suppress Applications Barcode OnLine Tools CityCode Design iPhone List Logs lsappinfo Memo Music perl PlistBuddy pluginkit postalcode ReadMe SF Symbols character id SF Symbols Entity sips Skype Slack sqlite TCC Tools Typography Video Wacom zoom