Skip to content

Instantly share code, notes, and snippets.

@benzado
Created July 25, 2011 23:16
Show Gist options
  • Save benzado/1105512 to your computer and use it in GitHub Desktop.
Save benzado/1105512 to your computer and use it in GitHub Desktop.
Optimize PNG Files
(*
Runs optipng command line tool on any selected image files.
*)
property optipng : "/opt/local/bin/optipng"
tell application "Finder"
set _selection to (selection)
set _images to {}
repeat with _item in _selection
if kind of _item ends with "image" then set _images to _images & {_item}
end repeat
if (count of _images) is 0 then
display alert "No image selected" message "You must select at least one image to optimize."
return
end if
repeat with _item in _images
set _name to displayed name of _item
set _path to POSIX path of (_item as alias)
set _command to optipng & " \"" & _path & "\""
do shell script _command
set _lines to paragraphs of result
set _status to item ((count of _lines) - 1) of _lines
display alert _name message _status
end repeat
end tell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment