Use FlexTime, LaunchBar, Spaces and AppleScript to get things done

January 13, 2011

As of late I've had a terrible time concentrating, on anything. So, I did what any self-respecting computer geek can't help but do, and rationalized further procrastination by telling myself I was going to create a new, usable workflow. The end result of this little productivity tangent is a combination of FlexTime, LaunchBar, Spaces and AppleScript, and does the following when set in motion:

Gives you 15 seconds to move into the Space where you're going to work.

Disables, after those 15 seconds have elapsed, your ability to switch between Spaces.

Lets you work in your chosen Space for 20 minutes.

Displays (using LaunchBar), after 20 minutes, "TAKE A BREAK!" in large type across the width of your monitor, and restores your ability to switch between Spaces.

Lets you do whatever you want for 5 minutes.

Displays, after 5 minutes, "TIME TO WORK!" (and then the steps repeat).

The whole thing is driven by a FlexTime routine (see the two images below), which consists of two activities that I call "Work" and "Play." The "Work" activity launches a first AppleScript when the activity starts, and a second AppleScript when the activity finishes, at which point the "Play" activity takes over and simply counts down some predetermined amount of time before the "Work" activity begins again. The routine repeats until you pause it.

When I first decided I was going to create this, my immediate thought was to simply disable Spaces for the duration of the "Work" segment and then re-enable it for the duration of the "Play" segment, but I quickly remembered that when you disable Spaces, the Spaces you're currently using disappear and all of your open applications get sucked into a single Space (i.e., your ‘main,' and now only desktop). If this is the type of functionality you want (I can't see why you would), then the below AppleScript is all you need; it just toggles Spaces on/off each time it's run.

tell application "System Events"
tell spaces preferences
tell spaces preferences
if ((spaces enabled) is true) then
set spaces enabled to false
else
set spaces enabled to true
end tell
end tell
end tell

After realizing that that wasn't what I wanted, my next thought was that I could completely disable Expose, but after digging around the OS I'm fairly certain that you actually can't disable it. However, you obviously can simply remove the ability for it to be invoked (via mouse clicks, hot corners, keyboard shortcuts, etc.), and so that's exactly what I did. (Relatedly, be sure to check the "Enable access for assistive devices" checkbox in the "Universal Access" pane of your System Preferences.)

To get this whole thing working, you'll first want to create two AppleScripts, one for each of the following two sets of code. You can call them whatever you like; I saved mine as time_to_work and take_a_break, respectively. Once the two AppleScripts are saved, all that's left to do is to create a FlexTime routine that looks like the one shown in the above two images.

using terms from application "FlexTime"
on HandleFlexTimeCue(myDocument, myRoutine)
tell application "LaunchBar"
display in large type "TIME TO WORK!" as text
delay 15
end tell
tell application "System Events"
activate
tell expose preferences
set properties of the bottom right screen corner to
{activity:none}
tell spaces preferences
set key modifiers of arrow key modifiers to {none}
set key modifiers of numbers key modifiers to {none}
end tell
end tell
end tell
tell application "System Preferences" to quit
end HandleFlexTimeCue
end using terms from

using terms from application "FlexTime"
on HandleFlexTimeCue(myDocument, myRoutine)
tell application "LaunchBar"
display in large type "TAKE A BREAK!" as text
delay 3
end tell
tell application "System Events"
activate
tell expose preferences
set properties of the bottom right screen corner to
{activity:show spaces}
tell spaces preferences
set key modifiers of arrow key modifiers to {option}
set key modifiers of numbers key modifiers to {option}
end tell
end tell
end tell
tell application "System Preferences" to quit
end HandleFlexTimeCue
end using terms from

(Note that the "set properties" lines in the examples above should be just a single line; I've broken them into two lines for presentation purposes only. Note further that your Spaces settings may be a bit different than mine, and so you'll want to make sure the values used in the above scripts are in line with how you use the utility (e.g., I use the bottom right corner of my screen to invoke Spaces).)