Sunday, April 8, 2007

Screenshots in xGestures

Just earlier today someone emailed me asking if there was some way to create gestures in xGestures that would take screen shots, like pressing command-shift-3.  I figured it would be a pretty simple thing, since you can create keystroke actions and just have one of those press command-shift-3.  What I found out is that even if you get passed the first hurdle of figuring out how to enter that keystroke the xGestures preference pane without actually taking a screenshot instead, it still doesn't work.  There's a bug in xGestures I'm going to try to address as soon as I get the chance to make those sorts of keystrokes work, because apparently any kind of system-level key command can't be triggered by xGestures.

Not to be defeated, though, I figured that maybe there was some kind of neat way to do it using AppleScript.  And sure enough, there is.  Hidden in Mac OS X is the unix command screencapture, which can be used to take screenshots in exactly the same way as pressing Command-Shift-3.  Unfortunately it requires you to give it a path to a file, rather than defaulting to saving the screenshot to the desktop in the form of 'Picture N', so I had to code something in there to make it do that on its own.  But here are three AppleScripts you can use with xGestures (or anything that can run AppleScripts, like Quicksilver) for taking screenshots:

This will take a screenshot normally, just like pressing Command-Shift-3:

repeat with i from 1 to 999
    set pathToTest to ("~/Desktop/Picture\\ " & i & ".png")
    try
        do shell script ("/bin/ls " & pathToTest)
    on error
        exit repeat
    end try
end repeat
do shell script "screencapture " & pathToTest



To make it behave like pressing command-shift-4, replace the last line with:
do shell script "screencapture -i " & pathToTest

or to make it behave like pressing command-shift-4-space, replace the last line with:
do shell script "screencapture -iW " & pathToTest

Hopefully someone might find these useful.  There's some other AppleScripts I wrote in response to user questions for xGestures, and at some point in the future I'll probably post them, since other people might like to have them too.

Introductory post

Hello to the cybermation info highway! I've started a blog because I just realized no more than fifteen minutes ago that I actually had a reason to write one. First, I'll get out of the way who I am: I am Brian Kendall. The general things I do include but are not limited to:
- Animation, mostly on computers but sometimes traditional animation
- Music composition, both instrumental and electronic
- Graphics programming
- Mac OS X programming and development
- Game development and design

That covers a lot of ground, so to give a better idea of what I do here are the actual things I'm actively involved with right now:
  • xGestures, a mouse gestures suite for Mac OS X
  • Software development for Anzovin Studios, including The Setup Machine and forthcoming products!
  • Pizazz!, the internets' hottest, happiest pop stars!


I'll mention more things as I start working on them. Aside from the work I've been doing for Anzovin Studios, I've been busy trying to complete more music compositions that I will probably post here at some point, and I'm probably going to start doing some very, very basic game development for the Xbox 360 using Microsoft's XNA game studio, but don't expect anything major to come from that anytime soon.

So what I'm going to do with this blog is post updates about the projects I'm working on that people might care about. For example, if I'm doing some kind of new work on xGestures, or I learned about or figured out some cool trick with it, I'll post that. (In fact, that's what my next post after this is going to be.) Or, if I have something neat or relevant to show for one of my other projects, I'll mention that. Really what it comes down to is that every now and then I develop or come up with cool things that are useful, neat, or practical involving computers or the internet or something like that, and I don't tell anyone about it, even though there's probably people out there who might find it really useful. So whenever something like that comes up, I'll post about it. This probably means I won't update the blog very often, because that doesn't really happen all that often, and I'm lazy. What this blog WON'T include is daily musings about my life, what my feelings are, or other mundane things about my day to day life because nobody wants to read that.

And that's that!