Wednesday, October 14, 2009

Convert Keynote / iWork 2009 to 2008

If you're like me, you tried Keynote 2009 and - while Keynote continues to be a superior presentation tool - decided that it wasn't worth the cost of upgrading. If you're even more like me, you created at least one presentation in Keynote 2009 during the trial (or converted a Keynote 2008 presentation to Keynote 2009 and tweaked it a bit), and were then quite dismayed to find that you could not open the Keynote 2009 file in Keynote 2008 at all. This is a big problem after the trial runs out - it leaves you with presentation material you can't recover!

The Keynote 2008 "file format" is really a directory structure. That is, each .key file is really a directory containing the information that Keynote uses to reconstruct the presentation. In Keynote 2009 this changed to a "flat file" format - they .key file really is a single file. Investigation reveals pretty quickly that the contents of that file are quite similar to the contents of the 2008 directory. A post by linux4research cleared this up - the 2009 format is actually a zipped archive! So half the battle is to simply rename the .key file to a .zip file, unzip it, then rename the unzipped folder with a .key extension. This still won't open in Keynote 2008, though. Luckily the other half of the battle is equally as simple. In they .key folder, open the file index.apxl, find the string key:version= followed by a quoted string that is probably something like 92008xxxxxx. Replace the number with 72007061400.

Anyways, here is a shell script that automates this process. I haven't tested it too extensively, but the basic idea should work. I haven't had experience with other iWork '09 programs (Pages, Numbers), but reportedly the differences are essentially the same, so it may work with them as well if you replace "key" with the proper extension.

# Dan Swain dan.t.swain at 10/14/09

# Bash script to convert Keynote 2009 format to Keynote 2008.
# Many thanks to linux4research's blog post
# (continued next line)
# (continued url) 2009/09/mac-keynote-2009-format.html
# for the .key to .zip step.

# input argument handling: DISABLED - I don't trust it enough
# not to erase your keynote file on accident...
# if -k is given as first argument, keep the original file
# and the output has "2008" added before .key
# otherwise the original file is overwritten (may be desirable
# because keynote files tend to be LARGE)
# if [ $# -ge 2 ] # note we may throw away extra arguments
# then
# if [ "$1" = "-k" ]
# then
# INPUT=$2
# KEEP=1
# else
# echo "Unknown argument $1, use -k to keep original file."
# exit
# fi
# else
# INPUT=$1
# KEEP=0
# fi

# safe input handling - need at least one argument
if [ $# -ne 1 ]
echo "Only one input argument allowed."

# basename doesn't work for keynote files...

if [ $KEEP -eq 1 ]
# output filename
OUTPUT=$OUTPUT" 2008.key"
# copy/rename to zipfile
echo "Copying $INPUT to $ZIPFILE, this may take a moment.."
echo "Done."
# output filename
# rename to zipfile

# unzip
echo "Unzipping $ZIPFILE."
unzip $ZIPFILE -d "$OUTPUT"
# erase the zipfile
echo "Erasing $ZIPFILE."
# change the version number in the index file
echo "Converting version string to 2008."
sed -i '' 's/version=\"[0-9]*/version=\"72007061400/g' "$INDEXAPXL"

Wednesday, September 16, 2009

Shell Script To List XCode Target Source Files

I develop a lot of c++ code on my mac for cross-platform applications, and I've often wanted a convenient way to export a list of source files belonging to a given target in an XCode project. That way when one of my colleagues wants to create a new project on another platform (e.g. Visual Studio or makefile) I can tell them which subset of the source tree to compile for a given application. I've looked several times for a solution but never had any luck. So finally last night I did what any programmer would do and I wrote my own shell script to parse this information out of the XCode pbxproj file.

I'm sharing it here because I'm not sure where else to post it, so if anyone has any suggestions let me know. I also had to learn a bit about awk and sed and I'm not a bash programmer by trade so I'm sure there is a more efficient/elegant/obfuscated way to do this - if anyone has suggestions please do share.

The pbxproj file is coded by long hex codes - so the trick was to find the section of the file that defines the names of the targets, then work forwards from there using the hex codes to find the right lines of the file and figuring out the right awk/sed commands to parse out the relevant information.

I've only tested this with XCode 3.1.3 and with only a single project, so I don't know how robust it is. It's at least a start. Thanks to for their quick source code formatter.


# Dan Swain dan.t.swain at 9/15/09

# Bash script to list the source files that are compiled for each target
# in an xcode project file.
# If an argument is specified, it is taken to be the name of the
# xcode project - the program looks for argument.xcodeproj/project.pbxproj
# If no argument is specified, the program searches for a .xcodeproject
# directory in the current directory. This probably won't work
# if there is more than one .xcodeproj directory.

# given the name of the project, this is the location of the project file
if [ $1 ]
XCODEPROJ=`find . -name '*.xcodeproj'`

# finds the lines defining the names of the targets
LINES=`sed -n '/isa = PBXNativeTarget/=' $PBXFILE`

# for each target
for LINE in $LINES
# the target name is on the previous line and is the second field
# delimited by *'s, we also remove a leading and trailing space
TARGETNAME=`awk 'NR=='$((LINE-1)) $PBXFILE | awk -F\* '{print $2}' | sed 's/^[ ]//;s/[ ]$//'`

echo Source Files for Target $TARGETNAME:
echo ====================================

# this is the hex code corresponding to the sources for this target
SOURCES=`awk 'NR=='$((LINE+4)) $PBXFILE | awk '{print $1}'`

# find the line numbers containing the hex code for the sources
# there are two of these, so this leaves us with just the last one
: # just want the last one

# the first file is 4 lines below this
# loop over the subsequent lines until the awk command fails
while [ "$OK" = "0" ]
# the source file is the third field
FILE=`awk 'NR=='$SL $PBXFILE | awk '{print $3}'`
if [ $FILE ]
echo $FILE
# next line

Friday, June 26, 2009

Recalling a day of our trip to SF

Originally uploaded by m0nstr42
Picture taken somewhere on Haight Street, San Francisco. I remember taking it around the time we were searching for Janis Joplin's house on Lyon Street, so I guess that makes it Upper Haight still, but the lower end? We walked all the way from the MUNI stop at Carl & Stanyan down the full length of Haight to Market Street, had lunch at a place called Cafe Trieste, and rode the F trolley all the way back around to the end of Fisherman's wharf. It was the first sunny day we'd had so we wanted to catch some views of the Golden Gate Bridge from the pier at the Maritime Park. It turned out to still be pretty hazy, so while we could *see* the bridge none of my photos came out all that well. We saw plenty of the bridge the next day, trust me.

Thursday, March 5, 2009

New Camera!

I'm the proud new owner of a Nikon D80 DSLR!  Or at least I was a month or so ago when I got it.  I don't update this very often, just when the mood strikes.  Anyways, I had been scoping DSLRs out for a couple months and decided to finally go for it (permission from my wife to spend a bunch of money was also key).  I picked up the D80 with two lenses; 18-55 mm f/3.5-5.6 VR and 55-200mm f/4-5.6 VR Nikkors.  I love it!  I take way too many pictures of our dog, but he's just so photogenic. Here's an example to commemorate the event.  I took this on the day I got the camera; we took Jack and went to Core Creek Park here in Newtown.  It was late afternoon, which is a great time to take pictures.  This is one of my favorite pictures I've taken so far with the new camera.

Monday, January 5, 2009

Yet another fresh start.

The whole "work blog" thing died after about one day, so that's gone. I'm really interested in getting an SLR this year (after the credit card is payed off from Cancun/Christmas/etc/etc), so maybe I'll go back to a regular blog kind of thing and post some pictures. Why not?

Here's a picture of the Old Church of St. Andrew here in Newtown. I took it late in the afternoon and was able to get the moon in the roof/steeple junction. The church dates to 1880, so it's actually relatively young in a town that was founded by William Penn in 1684. Historical!