Uli's Web Site
[ Zathras.de - Uli's Web Site ]
Other Sites: Stories
Pix
Abi 2000
Stargate: Resurgence
Lost? Site Map!
 
 
     home | blog | moose | programming | articles >> blogging

 Blog Topics
 
 Archive
 

15 Most Recent

 Less work through Xcode and shell scripts
2011-12-16 @600
 
 iTunesCantComplain released
2011-10-28 @954
 
 Dennis Ritchie deceased
2011-10-13 @359
 
 Thank you, Steve.
2011-10-06 @374
 
 Cocoa Text System everywhere...
2011-03-27 @788
 
 Blog migration
2011-01-29 @520
 
 All you need to know about the Mac keyboard
2010-08-09 @488
 
 Review: Sherlock
2010-07-31 @978
 
 Playing with Objective C on Debian
2010-05-08 @456
 
 Fruit vs. Obst
2010-05-08 @439
 
 Mixed-language ambiguity
2010-04-15 @994
 
 Uli's 12:07 AM Law
2010-04-12 @881
 
 Uli's 1:24 AM Law
2010-04-12 @874
 
 Uli's 6:28 AM Law
2010-04-12 @869
 
 Uli's 3:57 PM Law
2010-04-12 @867
 

More...

Blog Topics

There are four RSS feeds available for subsections of this blog:
News Announcements
Subscribe to this RSS Feed
Programming Stuff
Subscribe to this RSS Feed
Usability Stuff
Subscribe to this RSS Feed
Book and Movie Reviews
Subscribe to this RSS Feed
Stuff that strikes me Funny
Subscribe to this RSS Feed
Laws of programming that might help you track down stupid bugs
Subscribe to this RSS Feed

News Announcements

iTunesCantComplain released
(...)
Read More...2011-10-28 @954
Dennis Ritchie deceased

Apparently, a few days ago, Dennis Ritchie, the "R" in "K&R", co-creator of the C programming language has died.

Thank you for laying the groundwork for our profession, Mr. Ritchie.
Read More...2011-10-13 @359

Thank you, Steve.

Thank you, Steve.

[Screenshot of the Apple web site at the day of Steve Jobs's death]

We'll take it from here.


Read More...2011-10-06 @374
Blog migration
For the last few months, I have been progressively moving the blog to its new location at http://orangejuiceliberationfront.com. The RSS feeds have already been redirected, as have many of the articles and their comments. (...)
Read More...2011-01-29 @520
Downtime on Friday
The Zathras.de server (and my associated servers, i.e. the Masters of the Void tutorial) will probably be down for an hour or so on Friday for maintenance work at the provider. There's no need to worry, we plan to come back :-)
Read More...2010-03-04 @025

Programming

Less work through Xcode and shell scripts
Update: If you like this, you can find more scripting vaguely related to Xcode here.

Like most programmers, I'm not much a fan of repetitive work. I like to do the real work myself, while leaving the computer to take care of the drudgework. Among the most handy tools for this are scripts of all kinds. Having tried to fight AppleScript for a while, I finally realized that, while they may be uglier, shell scripts are a much better tool for this task. Here's a selection of my favorite shell scripts:

Delete Subversion folders

I use Subversion to keep track of my source code and to make it easy for me to undo any bigger changes I make. Sadly, Subversion litters all folders with its ".svn" folders. As of Xcode 1.5, when I add a folder reference to my "Resources" group, Xcode will also copy along those ".svn" folders, which are completely useless to end users and double the size of the executable. So, I've been adding the following bash script to a Shell Script Files build phase in most of my Xcode projects:

sudo find -d "${BUILD_DIR}/${PRODUCT_NAME}.app/Contents/Resources/" -name ".svn" -exec rm -r '{}' \; -print

This scans the generated application's "Resources" directory for any ".svn" folders and deletes them. The -d option is important here: It causes a depth-first traversal, meaning that if the ".svn" folder contains another file of the same name, it will be deleted first. Otherwise you get odd error messages because the deeper file has been deleted by the time find gets to it.

Auto-generating a Help Index

To get an index for your Help Book, and to be able to bring up anchors directly from code, you need to run the Apple Help Indexer on it. Since this is something I easily forget, I use the following script in another Shell Script Files build phase:

open -a /Developer/Applications/Utilities/Apple\ Help\ Indexing\ Tool.app ${BUILD_DIR}/${PRODUCT_NAME}.app/Contents/Resources/${PRODUCT_NAME}\ Help

or on Tiger:

open -a /Developer/Applications/Utilities/Help\ Indexer.app ${BUILD_DIR}/${PRODUCT_NAME}.app/Contents/Resources/${PRODUCT_NAME}\ Help


Note that open launches the indexer asynchronously, which means the build continues (and could finish) while the indexer is running. So, you may have to build the app a second time to make sure you don't get the old index.

Using PHP for your Help Books

One problem with help books is that they are restricted to being plain HTML files plus AppleScripts. There's really no nice way to "#include" a title or navigation area or a common design. PHP would let you do things like that. But PHP files need to be displayed through Apache, with PHP turned on in the httpd.conf. This would require you to install your help book in the user's Sites folder, mess with Apache's configuration, restart Apache and view your help through Safari (which doesn't have Help Viewer's great search feature, nor its facilities for integrating with your program).

But luckily, Apple started shipping along the new PHP command-line tool with MacOS X 10.3. So, if you can live with static content, you can generate HTML files from your PHP scripts through a simple command:

php script.php > page.htm

Of course, we want to automate this. We can use the find command to run this on all php files in a particular folder. But sadly, we can't have a redirect operator (">") in the -exec parameter to find. So, create a new shell script file "php2html.sh" and write the following script into it and chmod +x it:
#! /bin/bash
php "$1" > "$1.html"
This script will take a PHP file path as its parameter and create an html file with the executed script's output next to it. Once that's done, all you need is a shell script build phase:
dir="./${PRODUCT_NAME} Help/"
find -d "$dir" -name '*.php' -exec "${dir}php2html.sh" '{}' \; -print
And after that, maybe another call to find like above that deletes all the PHP source files after copying, or that copies everything but PHP files from the project directory. Neat, huh? Just remember to run your help indexing script after this one so there is something to be indexed.

Including the Subversion Revision in your App

I like to have the current SVN revision number somewhere in my app so there's a way to distinguish copies of the app even if I forget to bump up the version number. To do that, I use the following script:

#! /bin/bash

echo -n "Finding revision in "
pwd
revnum=`/usr/local/bin/svnversion . | cut -f '2' -d ':'`
# Now write the constant declaration to the file:
echo "#define SVN_VERSION \"$revnum\"" > svn_version.h
echo "Wrote revision $revnum to svn_version.h"

This creates a file named "svn_version.h" in the project's folder that contains the statement #define SVN_VERSION "46". I.e. you get a string constant that you can use in your C files wherever you want to display the current revision. It's important that this is a string, as a modified working copy gets a version number like "46M", which would cause trouble if you use an int.

Build and Upload File for Deployment

I also have a neat little shell script that switches my project's build style to "Deployment", builds it, compresses it and uploads it to a web server:

#! /bin/bashecho '===== BUILDING FILIE FOR DEPLOYMENT ====='
cd `dirname $0`
xcodebuild -project Filie.xcode -buildstyle Deployment clean build

cd build/
echo '===== CREATING ARCHIVE ====='
tar -czf Filie.tgz Filie.app

echo '===== UPLOADING ARCHIVE ====='
curl --upload-file Filie.tgz ftp://home-up.t-online.de/

echo '===== FINISHED ====='

Note that this script uses Tar/GZip, and thus can't cope with resource forks (though I've heard rumors that Tiger's command line tools have been changed to fix this). Also, you can use man curl to find out what parameters to include to authenticate with the FTP server to which you're uploading if your ISP doesn't pre-authenticate you like mine does.

I've put most of these scripts into files in my central library so I can just call them from Xcode, and to avoid code duplication that would make maintenance hard. I'd be interested in hearing what kinds of scripts you are using.


Read More...2011-12-16 @600
Cocoa Text System everywhere...
Sometimes, you need to draw text with more control than an NSTextField or NSTextView will let you do, and sometimes you need better performance than the NSStringDrawing category will provide. And maybe you need to draw text into a CGContext or even inside a Carbon application. (...)
Read More...2011-03-27 @788
Playing with Objective C on Debian
I felt like playing with Linux a bit, so I went and installed Debian on a partition. Apart from a few failed attempts to install it on an external drive (something which works fine with MacOS X, so I was spoiled) and a bit of confusion when it asked me for my drive name (how would I know a cryptic character combination like hdb4? And I selected that drive in your UI before, can't you let me use that same selector again?), it went pretty smooth. (...)
Read More...2010-05-08 @456
Uli's 12:07 AM Law
If your Objective-C++ code keeps crashing with an
invalid instruction exception
Your mental diarrhea made you forget to declare a method that takes C++ object by value. Since undeclared methods get a signature of -(id)methodName: ... and you can't pass a C++ object through such a variadic argument list, you get what you deserve.
Read More...2010-04-12 @881
Uli's 1:24 AM Law
If your custom accessibility objects don't get outlined on the screen by VoiceOver, chances are you nit passed a really small rect as the accessibility position/size for the containing accessibility object, and the sub views' outline is gone after it's been clipped to the superview sizes.
Read More...2010-04-12 @874

Usability

Hacking the Press - A point for usability in press kits
I once saw Adam Engst, of TidBITS fame, hold a talk called "Hacking the Press" at the Advanced Developers' Hands-on Conference (the first successor to MacHack). It was a great introduction to how the press works, told with the average programmer in mind, translating the life of a journalist into words we geeks can understand. I don't remember much of it in concrete details, but whenever the topic of press releases comes up, I realize that I know much more about this stuff than by all means I should, so I guess Adam managed to insinuate himself into my brain quite well. (...)
Read More...2010-02-18 @404
Double click is a shortcut
John Gruber mentioned in passing that people are confused about when to double-click and when not to. It's true, but that doesn't just apply to users. I've seen many application developers not knowing (or simply not caring) about when to use a double-click, and when not to. (...)
Read More...2010-01-16 @621
The Sinus Curve of Life
Certain events in life happen in circles. I think I got this piece of wisdom from my dad, back when I was a kid, and I keep seeing how true it is. The two examples I remember him giving me on different occasions were the recommended way of brushing your teeth and the progression from single-purpose power tools to integrated ones and back. (...)
Read More...2009-11-26 @430
Look and Feel Podcast launched
You may have noticed that it's been so nice and quiet. (...)
Read More...2009-08-18 @978
Why I don't want to be Delicious - Beyond the Unboxing Experience
Ages ago, most blogs I read were abuzz with talk about "the delicious generation". There was talk about "writing your own fucking HIG", about "steak versus sizzle", and many other beautiful and colourful phrases summarizing why and what the "Delicious" group of applications was (supposed to be). (...)
Read More...2009-07-05 @928

Reviews

Review: Sherlock
(...)
Read More...2010-07-31 @978
Review: G. I. Joe: The Rise of Cobra
G. I. Joe was a toy line from Hasbro with associated animated series in the 80ies that is virtually unknown here in Germany. The toys and a few movies were briefly released under the toy line's international name "Action Force" here, in Switzerland and a few other countries, but never really caught on. I used to watch it on an English cable channel as a kid. (...)
Read More...2009-08-26 @423
The Screaming Narwhal has Launched

[Screenshot from Tales of Monkey Island, Part 1: Launch of the Screaming Narwhal] (...)
Read More...2009-08-25 @423

Great movies and TV shows
I just read a top ten list of movies and realized I hadn't done reviews in a while. Two of the TV shows I reviewed last time have been canceled in the meantime: Blood Ties and Moonlight. While Moonlight got criticized by me for its derivative and pretentious nature, it was derivative of the right shows, and got an order for four more episodes after the strike, so I'd thought it might stay and at least give us a base level of vampire TV shows for the time being. (...)
Read More...2009-02-08 @109
Blood Ties, EFC and other TV fare
Since my last proper review blog posting, I've seen a bunch of stuff, so I thought I'd give you a short rundown. I just don't have enough time to write proper reviews of each and every one of them.

Blood Ties

(...)
Read More...2008-02-17 @568

Fun Stuff

Mixed-language ambiguity
The German verb "backen" means "to bake". Which of the two companies below, do you think, sells things for your back, and which one for baking? (...)
Read More...2010-04-15 @994
Very funny, Apple...
Very funny, Apple:
(gdb) po anInvocation
Some day, NSInvocation will have a useful debug description

Read More...2009-09-21 @702
Adding dates to the RSS feeds
Some newsreaders and aggregators out there apparently can't cope with feeds that contain no dates. Since the feeds on zathras.de fall under that heading, I've finally bit the bullet and changed my site to be more in line with their expectations. While I was at it, I also changed the RSS feeds to be full-text feeds instead of the short summaries they were before. (...)
Read More...2009-08-03 @379
How Mac OS X saves disk names...
Okay, so to reproduce a bug, I had to replace Helvetica with another font. My friend Flo grabbed a font with a name of the same length and just did a search-and-replace, and I dropped that in ~/Library/Fonts and I started testing. (...)
Read More...2008-03-07 @882
My Photoshop ate Opera!
There's a copy of Opera in /Applications/Photoshop Elements 3.app/Contents/MacOSClassic/
(...)
Read More...2008-02-09 @215

Laws of Programming

Uli's 12:07 AM Law
If your Objective-C++ code keeps crashing with an
invalid instruction exception
Your mental diarrhea made you forget to declare a method that takes C++ object by value. Since undeclared methods get a signature of -(id)methodName: ... and you can't pass a C++ object through such a variadic argument list, you get what you deserve.
Read More...2010-04-12 @881
Uli's 1:24 AM Law
If your custom accessibility objects don't get outlined on the screen by VoiceOver, chances are you nit passed a really small rect as the accessibility position/size for the containing accessibility object, and the sub views' outline is gone after it's been clipped to the superview sizes.
Read More...2010-04-12 @874
Uli's 6:28 AM Law
Get the _NSWarnForDrawingImageWithNoCurrentContext error message on your custom image rep? Don't pass a zero height to NSDrawBitmap(), you cognitive bluescreen!
Read More...2010-04-12 @869
Uli's 3:57 PM Law
If your XML doesn't parse due to a
closing tag not found
error, you mental bancruptcy have unquoted attributes on an opening tag. And yes, you're a moron for not quoting it, even if it is a number.
Read More...2010-04-12 @867
Uli's 4:41 PM Law
Leave the variable names in your prototypes, don't delete them because you think it looks cool. They serve as documentation.
Read More...2010-04-12 @864

 
Created: 2005-05-17 @777 Last change: 2011-12-16 @600 | Home | Admin | Edit
© Copyright 2003-2024 by M. Uli Kusterer, all rights reserved.