[UTType]処理対象のUTI(ファイルタイプ)か?チェックする 複数UTIでチェックする
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 |
006 | use AppleScript version "2.8" |
007 | use framework "Foundation" |
008 | use framework "AppKit" |
009 | use scripting additions |
010 | property refMe : a reference to current application |
011 | |
012 | |
013 | |
014 | set listUTI to {"public.png", "com.adobe.pdf", "public.jpeg"} as list |
015 | |
016 | |
017 | ##チェックする画像 |
018 | set strFilePath to ("/Library/Documentation/License.lpdf/Contents/Resources/Japanese.lproj/License.pdf") as text |
019 | set ocidFilePathStr to refMe's NSString's stringWithString:(strFilePath) |
020 | set ocidFilePath to ocidFilePathStr's stringByStandardizingPath() |
021 | set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath) isDirectory:false) |
022 | #URLのUTTypeを取得 |
023 | set listResponse to (ocidFilePathURL's getResourceValue:(reference) forKey:(refMe's NSURLContentTypeKey) |error| :(reference)) |
024 | set ocidUTType to (item 2 of listResponse) |
025 | ## |
026 | set boolUTIContain to false as boolean |
027 | repeat 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 |
035 | end repeat |
036 | #結果TRUEに変わっていれば画像かPDFと判断 |
037 | if boolUTIContain is true then |
038 | log "指定したUTIに含まれるファイルでした" |
039 | end if |
AppleScriptで生成しました |
| 固定リンク
「UTType」カテゴリの記事
- シンボリックリンクのUTIの取得(2024.12.02)
- [UTType]処理対象のUTI(ファイルタイプ)か?チェックする 複数UTIでチェックする(2024.10.03)
- [UTType]処理対象のUTI(ファイルタイプ)か?チェックする(2024.09.30)
- UTI(uniform type identifier)の取得 ツリー構造付き 少し修正(2024.06.19)
- UTI(uniform type identifier)の取得 ツリー構造付き(2024.05.23)