I don’t screencast a lot, but I do it enough to have a set pattern for preparing to record. I automated the process a few months ago and figured I’d share it.

The main script requires customization. There’s no way I could know what your pattern is, but it’s pretty easy to edit. There are enough methods demonstrated in it that you should be able to see how to extend it pretty easily. Or perhaps. as Ben Brooks suggested as a name for my podcast, “It’s easy. For me.”

I’ll start with a quick one-liner I use just to toggle my Desktop icons on and off for screencasting. It checks the current state and just flips it, so you can run the same command every time. You can run it as a script, alias it in your login profile or hook it up to Launchbar1 or Alfred2. Here it is, short and sweet:

defaults write com.apple.finder CreateDesktop `echo "($(defaults read com.apple.finder CreateDesktop)-1)*-1"|bc` && killall "Finder"

It runs a basic defaults write command to modify Finder’s Desktop icon preferences. To get the value and reverse it, it uses defaults read to get the current value and uses bc (a command line calculator built into the BSD subsystem) to calculate the opposite boolean value of the response. If that command succeeds without error, it relaunches Finder. If you happen to run TotalFinder, you can add && open -a TotalFinder at the end of the line.

Now the slightly longer script…

This script does the following:

Starting screencast mode:

  • Swap out my current wallpaper on my main screen for my standard screencast wallpaper, storing the path to the current wallpaper for restoration
  • Turn on Auto-hide for the Dock
  • Hide my main set of GeekTool desktop widgets
  • Hide the Desktop icons
  • (relaunch TotalFinder after restarting Finder)

Stopping screencast mode:

  • Turn off Dock hiding
  • Restore GeekTool
  • Restore my previous wallpaper
  • Show Desktop icons
  • (relaunch TotalFinder after restarting Finder)

The shell script version

You’ll need to customize just about every existing step (GeekTool group, wallpaper path, Dock preferences, etc.) and add your own for additional tasks. You could, for example, launch ScreenFlow and hide your other apps. Whatever works.

First, a bash version for command line use. It takes a single parameter (“start” or “stop”) and runs the appropriate series of commands:

#!/bin/bash
case $1 in
	'stop')
		osascript -e 'tell application "System Events" to set the autohide of the dock preferences to false'
		osascript -e 'tell application "GeekTool Helper" to set visible of group "Default Group" to true'
		osascript -e 'tell application "GeekTool Helper" to refresh'
		osascript -e "tell application \"Finder\" to set desktop picture to (POSIX file \"$(cat ~/.olddesktop)\")"
		defaults write com.apple.finder CreateDesktop 1 && killall "Finder"
		osascript -e 'tell application "TotalFinder" to launch'
		;;
	'start')
		osascript -e 'tell application "Finder" to return POSIX path of (desktop picture as alias)' > ~/.olddesktop
		osascript -e 'tell application "Finder" to set desktop picture to (POSIX file "/Users/ttscoff/Pictures/clothbackground.jpg")'
		osascript -e 'tell application "System Events" to set the autohide of the dock preferences to true'
		osascript -e 'tell application "GeekTool Helper" to set visible of group "Default Group" to false'
		defaults write com.apple.finder CreateDesktop 0 && killall "Finder"
		osascript -e 'tell application "TotalFinder" to launch'
		;;
	*)
		echo "Hides Desktop icons, Dock and GeekTool"
		echo "'start' to begin screencasting, 'stop' to restore state"
		echo "Usage: $(basename $0) [start -- stop]"
		;;
esac

The AppleScript/LaunchBar version

Here’s a LaunchBar Action version. It’s a regular on run handler, so you can actually run it from anywhere you can launch an AppleScript from (e.g. FastScripts or Alfred). Again, heavy customization needed for your workflow. This version toggles state using the visibility of your Desktop icons as an indicator of which mode you’re in. This assumes that under normal circumstances you keep your Desktop icons showing. If that’s not the case, you’ll be modifying the file anyway, so use a different boolean test in the first line of the on_run handler.

Open the script below in AppleScript Editor and save it as a compiled script (scpt) file. If you want to run it with LaunchBar, put it in ~/Library/Application Support/LaunchBar/Actions.

-- Script to toggle "screencast mode" (LaunchBar Action compatible)
-- Assumes you normally have your Desktop icons showing
-- and uses that boolean to determine which state to activate

-- Brett Terpstra (http://brettterpstra.com)
-- No license, all yours, modify at will

on run
	set current_state to do shell script "defaults read com.apple.finder CreateDesktop"
	if current_state = "1" then
		tell application "Finder" to set old_wallpaper to POSIX path of (desktop picture as alias)
		do shell script "echo " & old_wallpaper & " > ~/.olddesktop"
		tell application "Finder" to set desktop picture to (POSIX file "/Users/ttscoff/Pictures/clothbackground.jpg")
		tell application "System Events" to set the autohide of the dock preferences to true
		tell application "GeekTool Helper" to set visible of group "Default Group" to false
		do shell script "defaults write com.apple.finder CreateDesktop 0 && killall \"Finder\""
		delay 5
		tell application "TotalFinder" to launch
	else
		tell application "System Events" to set the autohide of the dock preferences to false
		tell application "GeekTool Helper" to set visible of group "Default Group" to true
		tell application "GeekTool Helper" to refresh
		set old_wallpaper to do shell script "cat ~/.olddesktop"
		tell application "Finder" to set desktop picture to (POSIX file old_wallpaper)
		do shell script "defaults write com.apple.finder CreateDesktop 1 && killall \"Finder\""
		delay 5
		tell application "TotalFinder" to launch
	end if
end run

That’s it, hope some other screencasters find it handy.

  1. For Launchbar you’ll need an AppleScript wrapper with a do shell script line to call this. 

  2. Alfred should be easier with its direct support for shell scripts, but I haven’t tried it.