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 |
---|
008 | use AppleScript version "2.6" |
---|
009 | use framework "Foundation" |
---|
010 | use framework "AppKit" |
---|
011 | use scripting additions |
---|
012 | property refMe : a reference to current application |
---|
013 | |
---|
014 | |
---|
015 | #画像か?のチェック用 |
---|
016 | property strUTI : ("public.image") as text |
---|
017 | |
---|
018 | ##チェックする画像 |
---|
019 | set strFilePath to ("/System/Library/Desktop Pictures/Solid Colors/Teal.png") as text |
---|
020 | set ocidFilePathStr to refMe's NSString's stringWithString:(strFilePath) |
---|
021 | set ocidFilePath to ocidFilePathStr's stringByStandardizingPath() |
---|
022 | set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath) isDirectory:false) |
---|
023 | #URLのUTTypeを取得 |
---|
024 | set listResponse to (ocidFilePathURL's getResourceValue:(reference) forKey:(refMe's NSURLContentTypeKey) |error| :(reference)) |
---|
025 | set ocidUTType to (item 2 of listResponse) |
---|
026 | #URLのUTTyepの親要素を取得して |
---|
027 | set ocidParentUTIArray to (ocidUTType's supertypes())'s allObjects() |
---|
028 | #親要素(この属性なら処理する)のUTType |
---|
029 | set ocidChkUTType to refMe's UTType's typeWithIdentifier:(strUTI) |
---|
030 | #含まれているか?チェックする |
---|
031 | set boolContain to ocidParentUTIArray's containsObject:(ocidChkUTType) |
---|
032 | if boolContain is true then |
---|
033 | log "含まれているので処理対象=画像ファイル" |
---|
034 | else if boolContain is false then |
---|
035 | log "含まれてない=画像ではない" |
---|
036 | end 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 |
---|
008 | use AppleScript version "2.6" |
---|
009 | use framework "Foundation" |
---|
010 | use framework "AppKit" |
---|
011 | use scripting additions |
---|
012 | property refMe : a reference to current application |
---|
013 | |
---|
014 | |
---|
015 | #画像か?のチェック用 |
---|
016 | property strUTI : ("public.image") as text |
---|
017 | |
---|
018 | ##チェックする画像 |
---|
019 | set strFilePath to ("/System/Library/Desktop Pictures/Solid Colors/Teal.png") as text |
---|
020 | set aliasFilePath to (POSIX file strFilePath) as alias |
---|
021 | #Finderを使ってUTIを取得する |
---|
022 | set strName to (name of current application) as text |
---|
023 | if strName is "osascript" then |
---|
024 | tell application "Finder" |
---|
025 | #Finder情報を取得して |
---|
026 | set recordInfoFor to info for aliasFilePath |
---|
027 | end tell |
---|
028 | else |
---|
029 | tell current application |
---|
030 | set recordInfoFor to info for aliasFilePath |
---|
031 | end tell |
---|
032 | end if |
---|
033 | #UTIを取得 |
---|
034 | set strItemUIT to (type identifier of recordInfoFor) as text |
---|
035 | set ocidUTType to (refMe's UTType's typeWithIdentifier:(strItemUIT)) |
---|
036 | set ocidParentUTIArray to (ocidUTType's supertypes())'s allObjects() |
---|
037 | #親要素(この属性なら処理する)のUTType |
---|
038 | set ocidChkUTType to refMe's UTType's typeWithIdentifier:(strUTI) |
---|
039 | #含まれているか?チェックする |
---|
040 | set boolContain to ocidParentUTIArray's containsObject:(ocidChkUTType) |
---|
041 | if boolContain is true then |
---|
042 | log "含まれているので処理対象=画像ファイル" |
---|
043 | else if boolContain is false then |
---|
044 | log "含まれてない=画像ではない" |
---|
045 | end if |
---|
AppleScriptで生成しました |
---|