Screenshot directory per active app.

I frequently take screen shots using command shift 4. That lets me select an area of the screen and save it as an image to my desktop. Is it possible to create a script that routes the image to a different folder depending upon what program is active?

Nice idea ” I could use this myself. I’m not sure if this qualifies as Applescript, but:

set a to path to frontmost application as text
set a to do shell script "echo '" & a & "' | sed 's/.*:\\(.*\\).app:/\\1/'"

set p to "/Users/lauri/Desktop/" & a
set qfp to quoted form of p
do shell script "mkdir -p " & qfp

set n to 1
	set n to do shell script "cd " & qfp & "; ls [0-9]*.png | sort -n | tail -1 | sed s/.png//"
	set n to n + 1
end try

set qfp2 to quoted form of (p & "/" & n & ".png")
do shell script "screencapture -io " & qfp2

-i → interactive, or capture selection instead of screen
-o → no shadows in single window screenshots

It could be smarter to use dates in the file names. Or to get the next numeric id from the highest number in ~/Desktop//.png. One more option would be to not use folders at all, but just add the name of the active application to each file.