[AppleScripts]iPhoneアプリ用に最適化されたPNGフォーマット“CgBI” iOS formatのPNGファイルを閲覧可能な形式に戻す
ちょろっとiPhoneApp用の画像を見たい時用
こんな画像を
見えるようにします。
アプリケーション形式のスクリプトに
pngcrushを内包させています。
スクリプトで言うと
↓この部分(10.6以外で動くか?はわかりません笑)
↑なぜこの処理が必要か?と言うと
本家Pngcrushのソースをコンパイルして
インストールしていると画像を元に戻す「-revert-iphone-optimizations」のオプションが無いからです。
1:ファイルを選んで(ドロップでも動きます)
2:デスクトップに書き出し先の『PngcrushExport』フォルダを作ります。
3:受け取ったファイルを順番に処理します
4:処理はpngcrush -revert-iphone-optimizations -d ディレクトリ 変換するファイル
5:全て終わったら出来たファイルを見せる
(*
iPhoneアプリ用に最適化されたPNGフォーマット
“CgBI” iOS format
CgBIフォーマットのPNGファイルを通常閲覧可能な形式に戻します
*)
-----------実行のはじまり
on run
-----------------【設定項目】ファイル選択ダイアログのデフォルトのディレクトリ
set theDefLoc to path to desktop from user domain
-----------------【設定項目】Uniform Type Identifier指定
-----------------詳しくは http://goo.gl/6jAQa Uniform Type Identifierを見てください
---set theFileType to "public.png,com.adobe.png" as text
---簡素の記述も出来ますPNGの場合-
set theFileType to "PNG" as text
-----------------↑のファイルタイプをリスト形式に整形する
set AppleScript's text item delimiters to {","}
set theFileTypeList to every text item of theFileType
-----------------【設定項目】プロンプトの文言改行が使えます\nを入れます
-----------------Uniform Type Identifierとメッセージ
set theWithPrompt to theFileType & "\nファイルをえらんでください\n"
-----------------残りのメッセージ
set theWithPromptMes to "ファイルをドロップしても\n動作します"
-----------------ダイアログを出して選択されたファイルは「open」に渡す
open (choose file default location theDefLoc ¬
with prompt theWithPrompt & theWithPromptMes ¬
of type theFileTypeList ¬
invisibles true ¬
with multiple selections allowed without showing package contents)
end run
------オープン(又はロドップ)のはじまり
on open theDropObj
-----------------【設定項目】フォルダを作成するディレクトリ
set theDeskTopPath to the path to desktop from user domain
-----------------【設定項目】かき出される画像の保存ディレクトリ名
set theExportFiles to "PngcrushExport" as text
-----------------フォルダを作成する(デスクトップにPngcrushExportフォルダを作成)
try
tell application "Finder"
make new folder at (theDeskTopPath) with properties ¬
{name:theExportFiles ¬
, owner privileges:read write ¬
, group privileges:read write ¬
, everyones privileges:read write ¬
}
end tell
end try
----------------出来たフォルダのパスをテキスト形式で取得しておく
set theSaveDir to (POSIX path of theDeskTopPath) & theExportFiles as text
----------------ドロップ実行か?スクリプトエディタで実行しているか?判定
----------------実行したアプリケーションのパスを求めて
set theMyPath to path to current application as string
----------------AppleScriptの文字が含まれているか?を調べる
if theMyPath contains "AppleScript" then
tell application "AppleScript Editor"
tell document 1
set theMyPath to path as text
end tell
end tell
----------------AppleScript Editorで開いている書類のパスにしておく
set theMyPath to (POSIX file theMyPath as text) & ":" as text
end if
---------------実行機器にインストール済みのpngcrushを使うか?判定
try
----------Developerディレクトリにpngcrushがある場合はDeveloperの方を使う
set thePngcrushPosPath to do shell script "mdfind -name pngcrush | grep \"Developer\""
on error
----------------内蔵のpngcrush(10.6x用)のパスにします
set thePngcrushPath to theMyPath & "Contents:bin:pngcrush" as text
----------------UNIXパスに整形
set thePngcrushPosPath to POSIX path of thePngcrushPath
end try
----------------コマンドラインを整形
set thePngcrushComLine to thePngcrushPosPath & " -revert-iphone-optimizations -d " & theSaveDir as text
----------------繰り返しのはじまり
repeat with theObjFiles in theDropObj
----------------ファイルのエイリアスをテキストに変換
set theFilePath to (POSIX path of theObjFiles) as text
----------------コマンドを実行
do shell script thePngcrushComLine & " " & quoted form of theFilePath
end repeat
---------処理が終わったら書き出し先のフォルダを開く
set theDefLoc to (POSIX file theSaveDir) as text
tell application "Finder"
activate
open theDefLoc as alias
tell window 1
set current view to icon view
end tell
end tell
end open
今回のワンポイントは
ドロップレット形式のスクリプトを
スクリプトエディタで開いて実行してもエラーにならいようにした
(ログ見ながら作成するのにとても便利)
| 固定リンク
「Apple」カテゴリの記事
- Business Essentials(2021.11.11)
- [MacOS12]zsh: command not found: php(2021.10.30)
- Automator と ショートカット(2021.10.27)
- Apple Style Guide(2020.08.01)
- あれれ?有線キーボード廃版?(2017.06.07)