AppleScript名:与えられた画像ファイルがNSImageでハンドリング可能かを取得 v2 |
— Created 2015-08-18 by Shane Stanley — Modified 2018-02-10 by Takaaki Naganoya use AppleScript version "2.4" use scripting additions use framework "Foundation" set oldPath to POSIX path of (choose file) set aRes to chkHandlingByNSImage(oldPath, "JPEG") –> {nsImageAcceptable:true, requireConvert:true} on chkHandlingByNSImage(aPath, targetFormatExt) set aRes to chkNSImageAcceptableFormat(aPath, targetFormatExt) set bRes to chkIsThereNeedToConvert(aPath, targetFormatExt) return {nsImageAcceptable:aRes, requireConvert:bRes} end chkHandlingByNSImage –与えられた画像ファイルがNSImageでハンドリング可能かを取得 on chkNSImageAcceptableFormat(aPath as text, targetFormatExt as text) — check if UTI of file is one NSImage can read set theWorkspace to current application’s NSWorkspace’s sharedWorkspace() set theType to theWorkspace’s typeOfFile:aPath |error|:(missing value) — returns UTI of file –> (NSString) "public.jpeg" set supportedTypes to current application’s NSImage’s imageTypes() — returns supported UTIs –> (NSArray) {"com.adobe.pdf", "com.apple.pict", "com.adobe.encapsulated-postscript", "public.jpeg", "public.png", "com.compuserve.gif", "public.jpeg-2000", "com.canon.tif-raw-image", "com.adobe.raw-image", "com.dxo.raw-image", "com.canon.cr2-raw-image", "com.leafamerica.raw-image", "com.hasselblad.fff-raw-image", "com.hasselblad.3fr-raw-image", "com.nikon.raw-image", "com.nikon.nrw-raw-image", "com.pentax.raw-image", "com.samsung.raw-image", "com.sony.raw-image", "com.sony.sr2-raw-image", "com.sony.arw-raw-image", "com.epson.raw-image", "com.kodak.raw-image", "public.tiff", "com.apple.icns", "com.canon.crw-raw-image", "com.fuji.raw-image", "com.panasonic.raw-image", "com.panasonic.rw2-raw-image", "com.leica.raw-image", "com.leica.rwl-raw-image", "com.konicaminolta.raw-image", "com.olympus.sr-raw-image", "com.olympus.or-raw-image", "com.olympus.raw-image", "com.adobe.photoshop-image", "com.microsoft.ico", "com.microsoft.bmp", "com.microsoft.cur", "com.truevision.tga-image", "com.sgi.sgi-image", "com.apple.macpaint-image", "com.ilm.openexr-image", "public.radiance", "public.mpo-image", "public.pbm", "public.pvr", "com.apple.rjpeg", "com.apple.quicktime-image", "com.kodak.flashpix-image"} if (supportedTypes’s containsObject:theType) as boolean is false then return "File format is unsupported" — check required type doesn’t already match else return true end if end chkNSImageAcceptableFormat –変換元の画像パスと変換対象の拡張子を与え、変換不要(同一ファイル"JPG"–> "JPEG"など)かをチェックする on chkIsThereNeedToConvert(aPath as text, targetFormatExt as text) set theWorkspace to current application’s NSWorkspace’s sharedWorkspace() set theType to theWorkspace’s typeOfFile:aPath |error|:(missing value) — returns UTI of file if (theWorkspace’s filenameExtension:targetFormatExt isValidForType:theType) as boolean then return false –"No conversion needed" else return true end if end chkIsThereNeedToConvert |
More from my site
(Visited 70 times, 1 visits today)