« [Spotlight]カラープロファイルで検索 | トップページ | ドロップレット基本フォーマット »

[UTType]処理対象のUTI(ファイルタイプ)か?チェックする


AppleScript サンプルコード

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

AppleScript サンプルソース(参考)
行番号ソース
001#!/usr/bin/env osascript
002----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
003#
004#  ファイルが画像か?のチェック
005#
006# com.cocolog-nifty.quicktimer.icefloe
007----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
008use AppleScript version "2.6"
009use framework "Foundation"
010use framework "AppKit"
011use scripting additions
012property refMe : a reference to current application
013
014
015#画像か?のチェック用
016property strUTI : ("public.image") as text
017
018##チェックする画像
019set strFilePath to ("/System/Library/Desktop Pictures/Solid Colors/Teal.png") as text
020set ocidFilePathStr to refMe's NSString's stringWithString:(strFilePath)
021set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
022set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath) isDirectory:false)
023#URLのUTTypeを取得
024set listResponse to (ocidFilePathURL's getResourceValue:(reference) forKey:(refMe's NSURLContentTypeKey) |error| :(reference))
025set ocidUTType to (item 2 of listResponse)
026#URLのUTTyepの親要素を取得して
027set ocidParentUTIArray to (ocidUTType's supertypes())'s allObjects()
028#親要素(この属性なら処理する)のUTType
029set ocidChkUTType to refMe's UTType's typeWithIdentifier:(strUTI)
030#含まれているか?チェックする
031set boolContain to ocidParentUTIArray's containsObject:(ocidChkUTType)
032if boolContain is true then
033  log "含まれているので処理対象=画像ファイル"
034else if boolContain is false then
035  log "含まれてない=画像ではない"
036end if
AppleScriptで生成しました

AppleScript サンプルコード

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

AppleScript サンプルソース(参考)
行番号ソース
001#!/usr/bin/env osascript
002----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
003#
004#  ファイルが画像か?のチェック
005#
006# com.cocolog-nifty.quicktimer.icefloe
007----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
008use AppleScript version "2.6"
009use framework "Foundation"
010use framework "AppKit"
011use scripting additions
012property refMe : a reference to current application
013
014
015#画像か?のチェック用
016property strUTI : ("public.image") as text
017
018##チェックする画像
019set strFilePath to ("/System/Library/Desktop Pictures/Solid Colors/Teal.png") as text
020set aliasFilePath to (POSIX file strFilePath) as alias
021#Finderを使ってUTIを取得する
022set strName to (name of current application) as text
023if strName is "osascript" then
024  tell application "Finder"
025    #Finder情報を取得して
026    set recordInfoFor to info for aliasFilePath
027  end tell
028else
029  tell current application
030    set recordInfoFor to info for aliasFilePath
031  end tell
032end if
033#UTIを取得
034set strItemUIT to (type identifier of recordInfoFor) as text
035set ocidUTType to (refMe's UTType's typeWithIdentifier:(strItemUIT))
036set ocidParentUTIArray to (ocidUTType's supertypes())'s allObjects()
037#親要素(この属性なら処理する)のUTType
038set ocidChkUTType to refMe's UTType's typeWithIdentifier:(strUTI)
039#含まれているか?チェックする
040set boolContain to ocidParentUTIArray's containsObject:(ocidChkUTType)
041if boolContain is true then
042  log "含まれているので処理対象=画像ファイル"
043else if boolContain is false then
044  log "含まれてない=画像ではない"
045end if
AppleScriptで生成しました

|

« [Spotlight]カラープロファイルで検索 | トップページ | ドロップレット基本フォーマット »

UTType」カテゴリの記事