[AppleScript] SIPS+ASで画像のピクセルサイズと解像度の取得
【スクリプトエディタで開く】 |
sipsASで画像のピクセルサイズと解像度.scpt.scpt | ソース |
|---|
| 001 | #!/usr/bin/env osascript |
| 002 | #coding: utf-8 |
| 003 | ----+----1----+----2----+----3----+----4----+----5----+----6----+----7-- |
| 004 | (* |
| 005 |
|
| 006 | System Events と スクリプトエディタに『フルディスクアクセス』が必要です |
| 007 | 不安に思われる場合は、実行しないようにしましょう |
| 008 |
|
| 009 |
|
| 010 | 一旦PLISTファイルにしてしまう方法 |
| 011 | ファイルのIOが発生するけど |
| 012 | 複数回コマンド打つより、本当にチョットだけ速い |
| 013 |
|
| 014 |
|
| 015 |
|
| 016 | com.cocolog-nifty.quicktimer.icefloe *) |
| 017 | ----+----1----+----2----+----3----+----4----+----5----+----6----+----7-- |
| 018 | use AppleScript version "2.8" |
| 019 | use scripting additions |
| 020 |
|
| 021 | set listUTI to {"public.image"} as list |
| 022 | try |
| 023 | tell application "SystemUIServer" |
| 024 | activate |
| 025 | set aliasFilePath to (choose file of type listUTI without multiple selections allowed) as alias |
| 026 | end tell |
| 027 | on error strErrMes number numErrNo |
| 028 | log strErrMes & numErrNo |
| 029 | return false |
| 030 | end try |
| 031 |
|
| 032 | #このパスは『System Events.app』にフルディスクアクセス権が必要 |
| 033 | #temporary itemsは起動時に自動で削除されるフォルダです |
| 034 | #ファイルは残らないので容量の心配はありません |
| 035 | set aliasTempDirPath to (path to temporary items from user domain with folder creation) as alias |
| 036 | set strTempDirPath to (POSIX path of aliasTempDirPath) as text |
| 037 | set strTmpFilePath to ("" & strTempDirPath & "sips.plist") as text |
| 038 |
|
| 039 | #コマンドにして |
| 040 | set strImageFilePath to (POSIX path of aliasFilePath) as text |
| 041 | set strCmd to ("/usr/bin/sips --getProperty allxml \"" & strImageFilePath & "\" > \"" & strTmpFilePath & "\"") |
| 042 | set strStdOut to (do shell script strCmd) as text |
| 043 |
|
| 044 | #コマンド作成されたPLISTを開いて値を取得する |
| 045 | tell application "System Events" |
| 046 | tell property list file strTmpFilePath |
| 047 | set numWpx to (value of property list item "pixelWidth") as integer |
| 048 | set numHpx to (value of property list item "pixelHeight") as integer |
| 049 | set numPPI to (value of property list item "dpiWidth") as integer |
| 050 | end tell |
| 051 | end tell |
| 052 |
|
| 053 |
|
| 054 | (* |
| 055 | SIPSのキー 画像から取得する時用 |
| 056 | bitsPerSample |
| 057 | dpiHeight |
| 058 | dpiWidth |
| 059 | format |
| 060 | formatOptions |
| 061 | hasAlpha |
| 062 | path |
| 063 | pixelHeight |
| 064 | pixelWidth |
| 065 | profile |
| 066 | samplesPerPixel |
| 067 | space |
| 068 | typeIdentifier |
| 069 | *) |
| AppleScriptで生成しました |
|---|