screenshot from selection


I need a script to make a screenshot where I can specify in pixels where on the screen the shot is from.
I’ve only seen code from scripts doing full screen shots.

This is one possible solution:

-- Grab Selection
-- The default output file is ~/Desktop/MySelection.tiff.
-- If it exists, then a sequential number is appended.
-- The file format can be changed to png, pdf, jpg or other formats. 
-- The cursor expanding the selected area shows the pixel count.
tell current application
	set existingFileNames to every paragraph of (do shell script "ls " & quoted form of POSIX path of (path to «class desk»))
	if "MySelection.tiff" is not in existingFileNames then
		set validName to "MySelection.tiff"
		set x to 1
		repeat until "MySelection" & space & x & ".tiff" is not in existingFileNames
			set x to x + 1
		end repeat
		set validName to "MySelection" & space & x & ".tiff"
	end if
	delay 3 -- time to promote an area of interest if necessary.
	do shell script "screencapture -i -t tiff ~/desktop/" & quoted form of validName
end tell

I need a script where I don’t manually specify the area of the shot. I want the script to specify in pixels the area.

Yeah, I’d like to have something like this too.

I’m not quite sure where your (Flex20’s) script designates the pixel coordinates.

Anyone else?


I believe you could make it happen by executing cliclick from a do shell script, performing the selection, before or after , executing screen capture from the next do shell script (with the -i option). (The do shell script which would need to go to the background in ordr to run the next do shell script would need to end with " 2>&1 >/dev/null &" or similar.) And I haven’t tried to ever select an area with cliclick, but I think it should work.