Need simple Applescript to Take Screenshot and save to Clipboard.

Hey guys,

I have been searching around this site to no avail.

i need simple Applescript to Take Screenshot and save to Clipboard, so that I can use this in my Automator workflow. The current Take Screenshot Action in Automator does not work.

Thanks a lot guys.

Regards,

Phil

Hello.

I’ll provide you with a way to read in an image file to the clipboard, this way, ( «class PNGf» ) works at least for jpeg files as well, since the files are stored with different formats. Which you can see if you log clipboard info.

set stuff to read alias "Hfs:path:to:pngfile" as «class PNGf»
set the clipboard to stuff

As far as I remember, there are several threads here concerning how to get a screen shot from applescript, but here is my take on it. (Having customized someone elses work. :slight_smile: )

As you can set where to store the files and so on, via defaults settings, I’ll leave it up to you, to figure out under what filename, and such. If you use Finder to sort every item by date of that item kind, then you should be able to get the correct name of the most recent screen shot. (You’ll find examples here.)

-- flat5 http://macscripter.net/viewtopic.php?id=38482
tell application "System Events" -- get frontmost process
	set frontmostProcess to first process where it is frontmost -- this will be the script process
	set visible of frontmostProcess to false -- hide the script process
	repeat while (frontmostProcess is frontmost) -- wait until the script is hided
		delay 0.2
	end repeat
	set secondFrontmost to name of first process where it is frontmost -- get name of frontmost process (ignoring the script process)
	set frontmost of frontmostProcess to true -- unhide the script process
end tell
tell application secondFrontmost to set winID to id of window 1 -- get WindowID of frontmost window of frontmost process
do shell script "screencapture -c -x -w "
--" & winID

-- -c is used to store it in the clipboard. -x is used to mute the sound. -l is used to refer to the prefered windowid.

Have a look at the thread referred to in the script, and man screencapture