Stealing Seconds Back from Xcode

October 14th, 2005

A lot of people like to complain about how Xcode is, in some ways, too slow. Especially when it comes to compilation time, developers who were familiar with CodeWarrior’s relatively blazing speed are often disappointed at the non-stellar performance of gcc in Xcode.

While we wait patiently for Xcode’s performance to improve, it’s important to make sure that we don’t waste any more time or frustration in the program than we need to. To that end, I am always looking for ways to automate those “repeat them all the time” actions I am liable to take in Xcode.

One of the tedious tasks I often find myself can be summarize in three easy words: “Reveal Active Product.” Unfortunately, the process is slightly less straightforward in all but the simplest of projects. One must first navigate through the Files & Groups tree to find the “Products” group. This group may or may not need to be disclosed to reveal its contents. Then the brain must be asked to do extremely menial work for a few moments as it decides which of the multiple products generated by this project is actually the one you’re interested in now. When these brain cells finally die, you’re left with a mouse right-clicking the item of interest, to locate and select the “reveal in Finder” item.

That’s too much work for me! I do this all the time. I need a keyboard shortcut. So, compliments of FastScripts and the following AppleScript, I am from this day forward using “Ctrl-Cmd-R” as a shortcut in Xcode for “Reveal Active Product.”

-- Get the active target's product as a posix path
tell application "Xcode"
	set myTarget to active target of active project document
	set myFile to product reference of myTarget
	set myPath to full path of myFile
end tell

-- Convert to an alias and ask Finder to reveal
set myAlias to POSIX file myPath
tell application "Finder"
	if exists myAlias then
		activate
		reveal myAlias
	else
		beep
	end if
end tell

If the active target’s product exists, the Finder will reveal it. If there is no such file, you get a beep. Enjoy!