« [NSRect]AppleScript式だと? | トップページ | [Acrobat]PDFにウォーターマーク・透かしを入れる(画像ファイルでもOK) 少し修正 »

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


AppleScript サンプルコード

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

AppleScript サンプルソース(参考)
行番号ソース
001#!/usr/bin/env osascript
002----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
003#  
004# com.cocolog-nifty.quicktimer.icefloe
005----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
006use AppleScript version "2.8"
007use framework "Foundation"
008use framework "AppKit"
009use scripting additions
010property refMe : a reference to current application
011
012
013
014set listUTI to {"public.png", "com.adobe.pdf", "public.jpeg"} as list
015
016
017##チェックする画像
018set strFilePath to ("/Library/Documentation/License.lpdf/Contents/Resources/Japanese.lproj/License.pdf") as text
019set ocidFilePathStr to refMe's NSString's stringWithString:(strFilePath)
020set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
021set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath) isDirectory:false)
022#URLのUTTypeを取得
023set listResponse to (ocidFilePathURL's getResourceValue:(reference) forKey:(refMe's NSURLContentTypeKey) |error| :(reference))
024set ocidUTType to (item 2 of listResponse)
025##
026set boolUTIContain to false as boolean
027repeat with itemUTI in listUTI
028  #親要素(この属性なら処理する)のUTType
029  set ocidChkUTType to (refMe's UTType's typeWithIdentifier:(itemUTI))
030  if ocidChkUTType = ocidUTType then
031    log "含まれているので処理対象=画像ファイル"
032    #初期値をTRURに変更
033    set boolUTIContain to true as boolean
034  end if
035end repeat
036#結果TRUEに変わっていれば画像かPDFと判断
037if boolUTIContain is true then
038  log "指定したUTIに含まれるファイルでした"
039end if
AppleScriptで生成しました

|

« [NSRect]AppleScript式だと? | トップページ | [Acrobat]PDFにウォーターマーク・透かしを入れる(画像ファイルでもOK) 少し修正 »

UTType」カテゴリの記事