The screencapture utility allows you to capture a window, a selection or the entire screen/monitor when executed. You can see the available options by typing screencapture in Terminal and pressing the Return key.
usage: screencapture [-icmwsWx] [file]
-i capture screen interactively, by selection or window
control key - causes screen shot to go to clipboard
space key - toggle between mouse selection and
window selection modes
escape key - cancels interactive screen shot
-c force screen capture to go to the clipboard
-m only capture the main monitor, undefined if -i is set
-w only allow window selection mode
-s only allow mouse selection mode
-W start interaction in window selection mode
-x do not play sounds
-S in window capture mode, capture the screen not the window
file where to save the screen capture
For example: typing screencapture -c -i -W will change the mouse pointer to a camera icon and as you move the pointer over the visible windows, each window will highlight. Clicking one time in a highlighted window takes snapshot of the window, and because we specified -c as an option, it places the image on the clipboard. If you remove the -W option from that line, the mouse pointer becomes a cross-hair and you can click and drag over a region of the screen.
You can change the screenshot format with the string in the Terminal. Log-out, re log-in required to change the format. But I didn't try it out (don't have 0.2. yet):
$ defaults write NSGlobalDomain AppleScreenShotFormat JPEG
Instead of JPEG you can also use TIFF, PNG, PICT.
$ screencapture -iW /dev/stdout | lpr
A good time to restate that if you only want to take a screenshot of a specific window, follow this instruction:
Press Command+Shift+4 on your keyboard
Press the Spacebar, the cursor will change from crosshair to a camera
Click the window you wish to capture with the camera cursor Done.
This command will also let you capture the Dock or the menubar as a window. You can grab individual icons and labels from the Finder. You can grab just the Desktop. Experiment!
To change the default location for screen captures so they get saved in a specific location instead of cluttering the desktop, you need to use the defaults command in the Terminal to change the path. It can be done like this:
Create the folder in which you want the screen captures to be saved in the location of your choice.
Open a Terminal window and type this: defaults write com.apple.screencapture location /Full/Path/To/Folder
Log out and log back in, and the change will have taken effect.
You have to put in the path properly. Using ~ to indicate your home folder will not work. The path must be entered starting from the root of the hard drive. For example, if you wanted to save them to a secondary partition, your path would start with /Volumes/SecondPartition/.
you can also simply do this from the terminal like so:
$ rex% sleep 5 ; screencapture ~/Desktop/capture.pdf
or you can use the -c option to capture right to the clipboard.
Here's a little perl script I came up with:
#!/usr/bin/perl
$number = "00000";
while(1) {
$newfile = $number.".jpg";
sleep 10;
`screencapture -m -x ~/Documents/$newfile`;
$number++;
}
What does it do? Simple - it takes a screenshot every 0 seconds and saves it as a .jpg file.
Can anyone tell me what's gained by using applescript to call the shell command, rather than just using this as a shell script? For example, I've written myself a little program that takes a screenshot every minute, converts it to jpg (using imagemagick), and saves it in my web directory:
#!/bin/sh
if [[ $# -ne 0 ]]
then
for id in `ps | grep screenie | cut -f 1 -d " "`
do
kill $id
done
cp /Library/WebServer/Documents/screenoff.jpg /Library/WebServer/Documents/screenie.jpg
exit 0
else
while (true)
do
screencapture /tmp/s.pdf
convert -page 1280x1024 -size 640x512 /tmp/s.pdf -resize 640x512 /tmp/s.jpg
cp /tmp/s.jpg /Library/WebServer/Documents/screenie.jpg
sleep 60
done
fi
Saved and appropriately chmoded, this will start taking screen shots if given no argument, and if given an argument, will kill all instances of itself (effectively shut down) and put up an “away” image.
Variante: Convert without imagemagick
#!/bin/sh
/usr/sbin/screencapture Bildschirmfoto.pdf;
/usr/bin/sips -s format jpeg Bildschirmfoto.pdf -o Bildschirmfoto.jpg;
I am surprised there is not a method from the keyboard but it does appear that you can select the main monitor as it is noted in the CLI. I made an applescript to as an amusement but also to simplify some of the added options. It also comes in handy on remotely controlled machines where the screen shot command is directed to the local machine. And here is the simple script I came up with that provides some feedback and reminds of options for usage.
display dialog "Capture screen or only an icon.
The highlight area shows capture.
Use 'shift' for crosshair capture.
Capture is on clipboard for paste.
ESC ends. " buttons {"OK"} default button 1
do shell script "screencapture -i -c -W"
Just attach that folder action to your desktop and any screen shots you make should automatically convert to PNG.
on adding folder items to this**folder after receiving these**items
repeat with an**item in these**items
tell application "Finder"
set file**name to name of an**item
set file**ext to name extension of an**item
if file**name starts with "Picture" and file**ext is "pdf" then
set png_path to my getSafeName()
tell me to convertToPNG(an**item, png**path)
end if
end tell
end repeat
end adding folder items to
on getSafeName()
set desk_path to (path to desktop as Unicode text)
try
alias (desk_path & "Picture 1.png")
set i to 0
repeat
set i to i + 1
set path**to**check to (desk_path & "Picture " & i & ".png")
try
alias path**to**check
on error
set png**path to path**to_check
exit repeat
end try
end repeat
on error
set png**path to (desk**path & "Picture 1.png")
end try
return png_path
end getSafeName
on convertToPNG(pdf**file, png**path)
tell application "Image Events"
launch
set image**ref to open pdf**file
save image**ref in png**path as PNG with icon
close image_ref
delete pdf_file
end tell
end convertToPNG