画像フォーマットをまとめて変換 [AppleScript辞書はつくれるか?]
(* 1) 画像ファイルをドラック&ドロップすると、指定の画像形式で書き出します。(1つでも複数のファイルでも可) 2) ダブルクリックで書き出し形式を変更できます。 3) 変換したファイルはデスクトップに "imageFolder" が自動で作成されて、そこに収められます。
※このスクリプトを保存するときには必ず「アプリケーション形式」で保存してください。 アプリケーションにしないと、ドラック&ドロップが働きません。 *)
property imageFormat : "PNG"
on run --|ダブルクリックで起動した時にこの部分が実行されます| --|選択するためのリストを表示して、選ばれた情報を記憶します| set ans to choose from list {"PNG", "JPG", "PDF", "BMP", "TIFF", "PSD"} with prompt "変換したい形式を選択:" set imageFormat to ans as string end run
on open dropItem --|ドラック&ドロップした時にこの部分が実行されます| -- display dialog ("画像を[ " & imageFormat & " ]形式で書き出してよろしいですか?" & return & return & "変更したい場合は、この後、アプリケーションをダブルクリックで起動してください") tell application "Finder" try make new folder at desktop with properties {name:"imageFolder"} end try set theOutputFolder to (path to desktop folder as string) & "imageFolder:" end tell repeat with obj in dropItem my imageChange(theOutputFolder, obj) end repeat end open
on imageChange(theOutputFolder, obj) tell application "Finder" to set fileName to name of obj if fileName contains "." then --|ファイル名から拡張子部分を削除して名前だけにする| set aText to (reverse of characters of fileName) as string set aText to text ((offset in aText of ".") + 1) thru -1 of aText set fileName to (reverse of characters of aText) as string --|指定の形式で書き出し| tell application "Image Events" launch set theImage to open obj tell theImage if imageFormat is "PNG" then save as PNG in ((theOutputFolder & fileName & ".png") as string) if imageFormat is "JPG" then save as JPEG in ((theOutputFolder & fileName & ".jpg") as string) if imageFormat is "PDF" then save as PDF in ((theOutputFolder & fileName & ".pdf") as string) if imageFormat is "BMP" then save as BMP in ((theOutputFolder & fileName & ".bmp") as string) if imageFormat is "TIFF" then save as TIFF in ((theOutputFolder & fileName & ".tif") as string) if imageFormat is "PSD" then save as PSD in ((theOutputFolder & fileName & ".psd") as string) end tell close theImage end tell end if end imageChange |
コメント 0