Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

I want to have an AppleScript that takes a screenshot of the front most application. I have used this AppleScript:

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 -l " & 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.

but it doesn't work for Snow Leopard. If anybody could give me some guidance as to what is the unsupported section of the code, I'd be happy to go and research myself.

I think Snow Leopard doesn't support the frontmost part but I can't get any information to back this assumption up...


Cmd+Shift+4 and Space and Click Window does work but I want an Applescript so I could replace the shortcut to open the Applescript - which will automatically take a picture of the active window.

This is so I don't have to click space and then click the windows I want.

I take screenshots a lot and constantly clicking space and clicking is getting annoying now.

The applescript, essentially, skips the space+click window

share|improve this question
    
Are you sure that the '-l' option to screencapture is supported in 10.6 ? It doesn't show up in the man page, or screencapture -h. –  Kent Jun 20 at 22:03
    
@Kent I'm very new to Applescript so I was naive enough to use the outputs posted online for screencapture -h thinking they were 10.6.8. Thanks, I just checked it on my Terminal as well. DO you know of any way to select windowid in 10.6.8? Because that's what the script is based around :) –  ṧнʊß Jun 20 at 22:59

2 Answers 2

up vote 1 down vote accepted

I just hacked together this little tool.

https://github.com/vorgos/QuickGrab

It is a command line tool that will capture the top most active window or any window you specify just like the -l option in the newer version of screencapture.

Hope that helped.

share|improve this answer

Taking a screenshot of the front-most window (via shift-command-4 spacebar click) won't suit?

share|improve this answer
1  
Yes it does, but I was wanting an Applescript so I could replace the shortcut to open the Applescript so it automatically takes a picture of the active window - so I don't have to click space and then click the windows I want. I take screenshots a lot and constantly clicking space and clicking is getting annoying now. –  ṧнʊß Jun 20 at 19:03

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.