3
  1. Open the Screenshot in Preview
  2. Select “Adjust Size…” from the Tools menu
  3. Change the Width and Height to 50 percent of the original
  4. Change the Resolution to 72 pixels/inch

I wish to do this on CLI with a generic command (percent, not actual width and height).

GUI instructions with Preview

5

You can do it with imagemagick by typing the following:

convert image.png -resize 50% -density 72 image.png

In order to execute the previous command you need imagemagick installed on your computer. You can easy do it via homebrew:

brew install imagemagick

And, if you haven't homebrew, you can install with this:

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
10

Take a look at the 'sips' command:

man sips

It is much simpler than GUI-scripting Preview and it's part of OSX. So you don't have to install anything. Example:

full_w=$(/usr/bin/sips -g pixelWidth image.jpg | /usr/bin/grep -Eo "[[:digit:]]+")
full_h=$(/usr/bin/sips -g pixelHeight image.jpg | /usr/bin/grep -Eo "[[:digit:]]+")
half_w=$(/bin/expr full_w / 2)
half_h=$(/bin/expr full_h / 2)
sips -z half_h half_w image.jpg
  • please provide the exact command. Like the imagemagick example. – Ivanov Jun 15 '15 at 12:15
  • Added an example script. A one-liner would look very confusing here. – awado Jun 15 '15 at 13:22
  • sips is a good answer as it is OSX native and light. imagemagick is good to know as the Swiss-army knive for image manipulation but might just be too heavy for only resizing. – CousinCocaine Jun 15 '15 at 13:34
  • thanks for example. imagemagick is much more user friendly than sips. Sips doesn't run on Linux and other UNIXes. – Ivanov Jun 15 '15 at 17:01
-1

Here is some applescript to just what you wanted, can be coupled with automator or fed into the command line program osascript like so:

osascript << 'END'
{applescript here}
END

You can add it into your ~/.bash profile as an alias for a command as well, so all you have to do is enter the downsize alias name and it will pop up, ask you which file you want to resize, and it does the rest automatically.

alias downsize="osascript << 'END'
{applescript here}
END"

Applescript:

tell application "Preview"
    activate
    try
        open (choose file with prompt "Pick file to modify")
    on error
        display dialog "Invallid selection!"
        return 1
    end try
end tell
tell application "System Events" to tell process "Preview"
    set frontmost to true
    click (menu item 1 where its title starts with "Adjust Size") of menu of menu bar item "Tools" of menu bar 1
    tell pop up button 1 of group 1 of sheet 1 of window 1
        click
        tell menu 1
            click menu item "percent"
        end tell
    end tell
    set value of text field 1 of group 1 of sheet 1 of window 1 to "50"
    set value of text field 2 of group 1 of sheet 1 of window 1 to "50"
    set value of text field 3 of group 1 of sheet 1 of window 1 to "72"
    click button "OK" of sheet 1 of window 1
    click (menu item 1 where its title starts with "Save") of menu of menu bar item "File" of menu bar 1
end tell
ignoring application responses
    tell application "Preview" to quit
end ignoring

Hope this helps!

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .