/dev/trouble
Eric Roller's Development Blog

An old trap that I keep to be falling into is this one:

> find . -name "Frameworks" -prune -or -name "Info.plist"
./Frameworks
./Info.plist

Notice how the Frameworks folder is also returned (since -prune defaults to true), but the intention was to exclude it! The solution is to add -print:

> find . -name "Frameworks" -prune -or -name "Info.plist" -print
./Info.plist

On Mac OS X 10.5 (Leopard) it appears to work fine, but when I quit my app, on a machine running 10.4 (Tiger), these messages appear in the Console:

2009-03-03 21:49:10.680 MyApp[6793] *** Illegal NSTableView data source
    (). Must implement numberOfRowsInTableView: and
    tableView:objectValueForTableColumn:row:
2009-03-03 21:49:23.139 MyApp[6793] *** -[NSCFString count]:
    selector not recognized [self = 0x1bc7f00]
2009-03-03 21:49:23.140 MyApp[6793] Exception raised during posting
    of notification.  Ignored.  exception: *** -[NSCFString count]:
    selector not recognized [self = 0x1bc7f00]

The interesting fact is that the MyApp class is the delegate of the NSTableView since it implements support for drag & drop. However, it is not designed to be the data source for the NSTableView. Instead, I use an NSArrayController through a binding in the NSTableView instance. This works fine until one quits.

What I suspect is happening (on Tiger) is that the NSArrayController is purged before the NSApp, which suddely remains as the only data source of the NSTableView, but without the access methods implemented.

The solution would be to implement dummy methods in the MyApp class for numberOfRowsInTableView: and tableView:objectValueForTableColumn:row: where one returns 0 and nil, respectively.

We can use iTunes to play music while we do circuit training, i.e. 40 seconds music while we work out, and 15 seconds pause while we rest or go to the next station:

  • save the following AppleScript in ~/Library/iTunes/Scripts; you will probably have to create the Scripts directory;
  • open iTunes with a suitable playlist; we recommend a good song and a Genius playlist;
  • select the first song;
  • launch the script from Scripts menu.

Note: There exists a newer version of this script!

(* AppleScript for circuit training with iTunes.
The default circuits are 40 seconds each, with pauses of 15 seconds.
At the beginning, the script asks for different times.

©2009, Eric Roller
*)

-- begin by asking for the workout and delay times
set tWork to the text returned of ¬
    (display dialog "Set the Workout Time [s]" default answer "40")
set tPause to the text returned of ¬
    (display dialog "Set the Delay Time [s]" default answer "15")

-- whether to skip to the next song, but only every other time
set skip to false

-- enter the forever loop
repeat
    -- start playing the music
    set volume without output muted
    tell application "iTunes" to play

    -- delay for 40 seconds by means of a dialog
    set answer to display dialog tWork & " Seconds Workout" ¬
        buttons "Stop" with title "Circuits Loop" ¬
        giving up after tWork
    -- stop if requested
    if the button returned of the answer is "Stop" then exit repeat

    -- stop the music, actually just mute it
    set volume with output muted
    if skip is true then
        -- every other time, change the track
        tell application "iTunes" to next track
    end if
    set skip to not skip

    -- wait 15 seconds (playing the song muted)
    set answer to display dialog tPause & " Seconds Pause" ¬
        buttons "Stop" with title "Circuits Loop" ¬
        giving up after tPause
    if the button returned of the answer is "Stop" then exit repeat
end repeat

-- finish by unmuting the volume and pausing iTunes
tell application "iTunes" to pause
set volume without output muted

Note that we go to the next track after every other workout. Also, since the volume is muted, we skip the first 15 seconds of every song. This is deliberate!

Let's first take a look at how Apache is configured (for Mac OS X 10.5.6 Leopard). In the Terminal:

> httpd -V
Server version: Apache/2.2.9 (Unix)
Server built:   Sep 19 2008 10:58:54
Server's Module Magic Number: 20051115:15
Server loaded:  APR 1.2.7, APR-Util 1.2.7
Compiled using: APR 1.2.7, APR-Util 1.2.7
Architecture:   32-bit
Server MPM:     Prefork
  threaded:     no
    forked:     yes (variable process count)
Server compiled with....
 -D APACHE_MPM_DIR="server/mpm/prefork"
 -D APR_HAS_SENDFILE
 -D APR_HAS_MMAP
 -D APR_HAVE_IPV6 (IPv4-mapped addresses enabled)
 -D APR_USE_FLOCK_SERIALIZE
 -D APR_USE_PTHREAD_SERIALIZE
 -D SINGLE_LISTEN_UNSERIALIZED_ACCEPT
 -D APR_HAS_OTHER_CHILD
 -D AP_HAVE_RELIABLE_PIPED_LOGS
 -D DYNAMIC_MODULE_LIMIT=128
 -D HTTPD_ROOT="/usr"
 -D SUEXEC_BIN="/usr/bin/suexec"
 -D DEFAULT_PIDLOG="/private/var/run/httpd.pid"
 -D DEFAULT_SCOREBOARD="logs/apache_runtime_status"
 -D DEFAULT_LOCKFILE="/private/var/run/accept.lock"
 -D DEFAULT_ERRORLOG="logs/error_log"
 -D AP_TYPES_CONFIG_FILE="/private/etc/apache2/mime.types"
 -D SERVER_CONFIG_FILE="/private/etc/apache2/httpd.conf"

Notice where the configuration file is (see last line); this is the file we would use if we enabled the web server from the System Preferences : Sharing : Web Sharing. However, we much rather not change that configuration file; instead we shall simply supply a different one that we keep outside the /private/etc area.

[more]

Before we go ahead with our personal configuration file, it is a good idea to compare our settings to those provided by Apple; use a "diff" tool of your choice (I like twdiff that comes with BareBones' TextWrangler). Once our settings are complete, we shall begin with a syntax check:

> apachectl -f /path/to/conf/httpd-debug.conf -t
Syntax OK

To launch Apache with our own configuration, we run:

> sudo apachectl -f /path/to/conf/httpd-debug.conf -k start

To verify that it is running, we can issue this command (when o.k. we will get multiple lines for multiple httpd instances):

> ps -e | grep httpd | grep usr

Finally, to view the web site in Safari, we simply open the location: http://localhost/ .

Following the instructions on DroboShare, the Drobo disk must be reformatted as "MacOS Extended", i.e. not journalled. Furthermore, to prevent Time Machine from filling up the Drobo indefinitely, one may like to partitioned it:

Partition 1: Tardis (500GB) ... for Time Machine Partition 2: Dalek (1.5TB) ... for general use

Next problem was to copy the previous Time Machine image onto the new partition. For better performance, we did this with both the old backup disk (Diskus) and the Drobo (Tardis & Dalek) connected. This suggestion from an arstechnica forum appeared to do the trick:

sudo /usr/local/rsync/bin/rsync -aNHAXx --protect-args --fileflags \
    --force-change /Volumes/Diskus/Backups.backupdb /Volumes/Tardis

NB. that this is not the rsync that came with Mac OS X, but version 3.0.1 that we have compiled with support for extended attributes.

Searched for it online and found this solution, which worked fine for me (Xcode 3.0):

defaults write com.apple.xcode  PBXCustomTemplateMacroDefinitions  \
        '{ ORGANIZATIONNAME = "tredje design"; }'

Seen errors like this, e.g. upon "svn update" issued on a remote machine when the repository is on a server:

svn: Berkeley DB error for filesystem '.../Repositories/proj/db' while
opening 'nodes' table: Invalid argument
svn: bdb: file nodes (meta pgno = 0) has LSN [95][515282].
svn: bdb: end of log is [95][14597]
svn: bdb: .../Repositories/proj/db/nodes: unexpected file type or
format

Not sure what the main cause is, but it could be a bug with svnserve since it is the one who is running as root. Login with ssh on the server and cd to the directory mentioned in the error:

cd Repositories/proj/db
ls -l
[...]
-rw-r--r--   1 root  goblin   1048576 Aug  4 17:42 log.0000000095
-rw-r--r--   1 root  goblin   1048576 Aug  4 17:52 log.0000000096

Notice that there are files whose owner is root while the other files (not shown) are owned by globlin. We can fix that with chmod:

sudo chown goblin log.000000009*
cd ../..
svnadmin recover proj

Back on the remote machine, try again to run "svn update".

The goal is to access the preferences of a second application and to be able to change those preferences. I thus tried:

theDef = [[NSUserDefaults standardUserDefaults] retain];
[theDef addSuiteNamed:MyHelperAppDomain];

However, when a setting was changed and when I instruct the NSUserDefaults class to synchronize, the changes are not saved in the MyHelperAppDomain. This is because addSuiteNamed: only adds the settings from that domain; it does not change the domain!

How did I find the mistake? Tried this command in the Terminal:

> defaults find DateFormat
Found 1 keys in domain 'se.tredje.myapp': {DateFormat = "%+"; }
Found 1 keys in domain 'MyHelperApp': {DateFormat = "%F"; }

To change the preferences for a different application domain, I have found this alternative:

CFPreferencesSetAppValue( (CFStringRef) DefaultDateFormat,
    (CFStringRef) DefaultDateFormatDefault,
    (CFStringRef) MyHelperAppDomain );
CFPreferencesAppSynchronize( (CFStringRef) MyHelperAppDomain );

Saw this before version 2.2.2 and the solution was to use the current beta version of Apache (2.1.8-beta I think). Now I see it again for the new photo page.

Found some online forum message where they suggested to change the output_buffering value in /usr/local/lib/php.ini to something like "1048576" (1MB). I don't have pictures that large so I set it to "512000" (500kB). This solved the problem for me.

While searching for the culprit that is responsible for the AirTunes cut-outs, I thought it might be a good idea to try disabling Spotlight and Dashboard.

Two steps are necessary, first turn Spotlight off in the hostconfig file, then disable indexing and remove the existing indexes with mdutil:

> sudo vi /etc/hostconfig
vi> Go
SPOTLIGHT=-NO-
vi> ZZ
> sudo mdutil -i off /
> sudo mdutil -E /

You can then use Activity Monitor to kill any mds or mdimport processes or else just reboot.

If you later change your mind and decide you want Spotlight after all, it's easy to reactivate. Set SPOTLIGHT=-YES- in /etc/hostconfig, run in Terminal:

> mdutil -i on /</pre>and reboot.

Disabling Dashboard

To turn Dashboard off:

> defaults write com.apple.dashboard mcx-disabled -boolean YES

To turn Dashboard on:

> defaults write com.apple.dashboard mcx-disabled -boolean NO

You have to restart the Dock after making either change for it to take effect:

> killall Dock

(NB. Neither turned out to be the culprit for AirTunes. It was the broadband router which dropped more and more packages until it died a couple of months later.)