Mac OS X
Apache 2.2.4 Universal Binary
Long story short, I needed a server-side Python interpreter. For this there's two options (that I know of) - install Zope and run it along or in place of your existing web server (probably what any intelligent being would do), or go the hard way and run mod_python instead. The latest version works with either httpd 2.0 or later so it won't run OOtB on OS X. I figured since I'm upgrading my Apache anyway, I may as well grab the latest version. Turns out there's actually no OS X package out there for that (not counting the XAMPP monster, which is Intel-only). OK, no biggie I'll roll it myself - and why not make it UB as well.

> ./configure --prefix=/usr/local/httpd-2.2 --enable-isapi --disable-mem-cache --enable-mime-magic --enable-ssl \
--enable-http --enable-dav --enable-cgi --enable-rewrite --enable-so --enable-headers --with-ldap --enable-dbd \
--enable-auth-digest --enable-authnz-ldap --enable-authn-anon --enable-mods-shared=most --enable-ldap --enable-cache

I think those features should make it more or less usable also in a real server environment.

Then, due to a bug in GNU libtool, you have to manually replace all the sys_lib_search_path_spec lines in two files - srclib/apr/libtool and srclib/apr-util/xml/expat/libtool to
sys_lib_search_path_spec="/Developer/SDKs/MacOSX10.4u.sdk/usr/lib"

After compiling and installing I had to go through the config files to make it more of a drop-in replacement for Apache 1.3. So that it works nicely with what's already there without actually replacing anything. Simply start with config/httpd.config and work through it and all the included files to check for any "incompatibilities" with OS X (document rooot, the www user, homedirs, tmp dirs, the usual).

Finally you just need an interface to control the server. Some fancier distros come with PrefPanes, mine simply has a StartupItem with the service name "Apache 2.2". You set this up by adding something in /etc/hostconfig (like APACHE22=-YES-) and then the relevant StartupItem into /LibraryStartupItems. So finally, to start our new server:
> sudo SystemStarter start "Apache 2.2"

You can't use launchd because it's not appropriate for wrapping things like apachectl.

Currently things seem to run nicely, I'm still testing stuff before maybe building a package. WebDAV works, which is nice.

It's incredible how many things you have to keep in mind to finally get a successful build out, a lot due to the fact that configure scripts don't seem to do any sanity checking between the different switches. For example, you can enable DAV, but if you forget to add any auth modules, nothing will work. Or the fact that --with-ldap and --enable-ldap are two different things - and you only find out that the first one (which isn't even mentioned in --help, btw) is compulsory if you want to add any kind of LDAP support. It took a lot of TTA to finally get this far...
|
Emulators over RDC
Always remember to keep the sound option at "Play on remote computer". I tend to leave mine at "Do not play" and then wonder why the S60 emulator will launch and then quit after about 20 seconds.

Pasted Graphic

|
As If Nothing Ever Happened
To restore a customised and updated machine so that it looks as if it's never been booted:

Boot to single-user mode
> mount -uw /
> rm -rf /Users/* /var/db/netinfo/local.nidb /var/db/.AppleSetupDone /Library/Preferences/* /Library/Caches/*
> shutdown now

|
Revitilizing Camino's Flashblock
I noticed the little FlashBlock checkbox in CaminoTools wasn't actually doing anything. It's supposed to disable all flash content until you click on it. Turns out this is achieved with simple CSS and here's how you enable it:
> cd ~/Library/Application\ Support/Camino/chrome
> cat > ./flashblock.css << EOF
/* Prevent flash animations from playing until you click on them. */
object[classid$=":D27CDB6E-AE6D-11cf-96B8-444553540000"],
object[codebase*="swflash.cab"],
object[type="application/x-shockwave-flash"],
embed[type="application/x-shockwave-flash"]
{ -moz-binding: url("http://www.cs.hmc.edu/~jruderma/clickToView.xml#ctv"); }
EOF

and then just include that css file in your userContent.css:
> echo "@import url(flashblock.css);" >> ./userContent.css

I think this is a pretty useful thing to do to Camino since many Flash objects seem to slow it down to a crawl.
|
Giving .doc an Icon
I don't work much with Word files, but when I do, the only major "problem" I have is that if you only have Pages and TextEdit installed, .doc files have a generic-looking white icon. It's easy to fix though:

/Applications/TextEdit.app > Show package contents > Contents > Resources
Duplicate rtf.icns and rename copy to doc.icns
From the Contents folder open Info.plist and into the CFBundleDocumentTypes array append:
<dict>
<key>CFBundleTypeExtensions</key>
<array>
<string>doc</string>
</array>
<key>CFBundleTypeIconFile</key>
<string>doc.icns</string>
<key>CFBundleTypeName</key>
<string>Microsoft Word Document</string>
<key>CFBundleTypeOSTypes</key>
<array>
<string>W8BN</string>
<string>W6BN</string>
</array>
<key>CFBundleTypeRole</key>
<string>Editor</string>
</dict>

Then flush the LaunchServices cache (this will reset all document/app associations so be prepared to be annoyed):
> cd /System/Library/Frameworks/ApplicationServices.framework/Frameworks/LaunchServices.framework/Support
> ./lsregister -kill -r -domain local -domain system -domain user

Pasted Graphic 1

|
Display Sleep
I usually leave my Mac on when I go to bed. This means setting the display sleep to now or the next best thing, 1 minute. The most obvious way to do it is from System Prefs, but I wanted something faster:
> sudo pmset displaysleep 1

is great, but requires root prvileges (due to some of the other things you can do with it) so it's out for any kind of automation/scripting purpose.

Enter Apple Remote Desktop. Among other niceties, ARD includes a CLI utility called systemsetup that you can use to set various system preferences, like so:
> /System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Support/systemsetup -setdisplaysleep 30

Nice. Time to wrap this into something Mac-like and give it a keyboard shortcut:
property ARDPath : "/System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Support/systemsetup"

set currSleep to do shell script ARDPath & " -getdisplaysleep"

if (currSleep) does not end with "1 minutes" then
set newSleep to 1
else
set newSleep to 30
end if

do shell script ARDPath & " -setdisplaysleep " & newSleep

Throw that into ~/Library/Scripts and give it a fitting shortcut in System Prefs/Keyboard & Mouse.
|
Audio Transcoding with Automator
Got a bunch of FLAC files that I wanted to add to the iTunes library. Options: a) install the FLAC component and hope it works b) decode them with flac, import wavs to iTunes, delete the wavs or c) do point b), but with a click of a button:

Pasted Graphic

Pretty nice. I only wish QuickTime Player had such a nice Automator Library...

|
Points on ZFS
* Snapshots. This feature was the reason people originally thought it was behind Time Machine.

"A snapshot is a read-only point-in-time copy of a filesystem which takes practically no time to create and uses no additional space at the beginning. Any snapshot can be cloned to make a read-write filesystem and any snapshot of a filesystem can be restored to the original filesystem to return to the previous state."

Because this is implemented on the fs level, it's very fast and totally transparent.

* Dynamic striping. ZFS not only promises much improved consistency, but also performance. Dynamic striping allows to write to all devices in a "pool" simultaniously.

Here's a nice 10-point list of the advantages and a Flash animation of ZFS in action.

Boot support is not actually implemented in the FS. Because it's such a low-level thing, it has to be implemented in the actual hardware (ROM). This is definitely something that will set the PPC and Intel Macs apart one day since the Intel machines have EFI which is a modern programmable BIOS that Apple will probably one day update to support booting from ZFS.
|
IOHWSensor
Q: Is it possible to read the hardware sensors from the Terminal, without any 3rd party help?
A: Yes it is.
Q: Mmkay, but how?
A: I'm glad yo asked. With ioreg and a few extra utilities, like awk:
ioreg -n IOHWSensor | awk -F "=" '/\"current-value\" = (\d*)|\"location\" = (\d*)/ { print ($2); }'

That will output:
 3031040
"HDD BOTTOMSIDE"
3309568
"CPU TOPSIDE"
3440640
"GPU ON DIE"
80033
"CPU CORE"
307429376
"REAR MAIN ENCLOSURE"
1900544
"BATTERY"

As you can see the numbers don't make any sense. And this where the amazing "Mac OS X System Internals" comes in. In chapter 10.7 "A Programming Tour of the I/O Kit's Functionality" (page 1307) we find that the values should be bit shifted right by 16. So here's another example, in Python, with the bit shift applied:
import commands
ioreg = commands.getoutput ('/usr/sbin/ioreg -n IOHWSensor')
k = re.findall ("\"location\" = \"(.*?)\"", ioreg)
v = re.findall ("\"current-value\" = (\d*)", ioreg)

aDict = dict (zip ([lower (el) for el in k], [int (el) >> 16 for el in v]))

Giving us the temps in centigrade:
{'gpu on die': 52, 'battery': 29, 'cpu topside': 49, 'rear main enclosure': 4732, 'cpu core': 1, 'hdd bottomside': 46}

This code also wraps the results in a nice Python dictionary. 'rear main enclosure' is obviously the RPM of the only fan this machine has.

Here's the output from running the shell command on a G5:
476
"CPU T-Diode"
107
"CPU Current"
823
"CPU Voltage"
124
"Slots Power"
2097152
"DRIVE BAY"


hw_prefs machine_type

Many thanks to all the people who helped me piece this one together!
|
Find out Correct Base Install Permissions
Found this little nugget of information while going through the Package Maker help:

lsbom -p MUGsf /Library/Receipts/BaseSystem.pkg/Contents/Archive.bom
|
SQLite 3.3.7 Package
Available here. Universal, no TCL extension.

|
Subversion 1.4 Package
Available here. Built as Universal binary. Also includes SVN book PDF. Installs into /usr/local, no Apache support (wouldn't work with 1.3 anyways).

|
nmap and wget packages
Binaries as PKG available here and here. Both universal.

Making them was really easy. Just create a sparse image, and ./configure with --prefix=/Volumes/MyImage
Then set that as the root in PackageMaker and check perms etc.

|
Empty Trash
You'll notice there's no "Empty the trash" Automator action. There are those who will try to sell you this action. But why?
Add Automator > Run AppleScript action and:

tell application "Finder"
empty trash
end tell

Can I have some money now? :D

|
UnitInfo and Punk Released
Available on the Software page. Huge thanks to Martin for the graphics and UI design!

|
What's SourceCache?
Working with different tools in OS X, you'll often notice these paths show up in console.log:
/SourceCache/JavaScriptCore/JavaScriptCore-418.3/bindings/objc/WebScriptObject.mm
/SourceCache/apache_mod_php/apache_mod_php-18.4/php/configure

What are they?
My guess is they're the development environment directories at Apple.

|
KDX MacUnix
Copy app to /Applications/KDXServer1600, try and run it. Define shares and link folders if necessary:

ln -s /my/shared/folder /Applications/KDXServer1600/Bases/Default/Downloads.

Create a LaunchDaemon (from haxial.com):

sudo nano /Library/LaunchDaemons/com.haxial.kdxserver.plist

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.haxial.kdxerver</string>
<key>ProgramArguments</key>
<array>
<string>/Applications/KDXServer1600/KDXServer.command</string>
<string>--bkgnd</string>
<string>--nohup</string>
</array>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>

Load the daemon:
$ launchctl load -w /Library/LaunchDaemons/com.haxial.kdxserver.plist
$ launchctl start com.haxial.kdxserver


http://developer.apple.com/macosx/launchd.html
man 5 launchd.plist
|
pidof
Here's one way of recreating that handy utility. I'm assuming that the utility is always run after the program we're looking for, so it has a smaller PID

fiBook:~ filipp$ ps A | grep something | grep -v grep | awk '{print $1;}'

|
Repair Permissions != Chumbug
Contrary to popular belief, Disk Utility's Repair Permissions function can be very helpful. Here's an example:

Software Update wouldn't work ("There were errors bla-bla-bla). Installing from PKG gave a better error (checking from install log) something about broken DiscRecording Frameworks. Repair Permissions had this to say:

Symbolic link ./System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/CFNetwork.framework/Versions/Current->A repaired
Symbolic link ./System/Library/Frameworks/DVDPlayback.framework/Versions/Current->A repaired
Symbolic link ./System/Library/Frameworks/DiscRecording.framework/DiscRecording->Versions/Current/DiscRecording repaired
Symbolic link ./System/Library/Frameworks/DiscRecording.framework/Frameworks->Versions/Current/Frameworks repaired
Symbolic link ./System/Library/Frameworks/DiscRecording.framework/Resources->Versions/Current/Resources repaired
Symbolic link ./System/Library/Frameworks/DiscRecording.framework/Versions/A/Frameworks/DiscRecordingContent.framework/Versions/Current->A repaired
Symbolic link ./System/Library/Frameworks/DiscRecording.framework/Versions/A/Frameworks/DiscRecordingEngine.framework/Versions/Current->A repaired
Symbolic link ./System/Library/Frameworks/FWAUserLib.framework/Versions/Current->A repaired
Symbolic link ./System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current->A repaired
Symbolic link ./System/Library/PrivateFrameworks/AppleVA.framework/Versions/Current->A repaired
Symbolic link ./System/Library/PrivateFrameworks/BezelServices.framework/Versions/Current->A repaired
Symbolic link ./System/Library/PrivateFrameworks/Bom.framework/Versions/Current->A repaired

After this and a 10.4.7 Combo Install, the machine worked fine again.

Another example, Activity Monitor wouldn't start, system.log had this to say:

2006-10-17 16:07:18.904 Activity Monitor[21307] The tool is not setuid root - please repair the privileges

Needless to say, repairing permissions fixed the problem. I've also seen cases where no application would launch - meaning you get the "blinking desktop" problem with the Finder constantly trying to start itself up. It was caused by a broken /tmp symlink (which in OS X links to /private/tmp, and we also have /var/tmp!) which Disk Utility nicely repaired.

Repair Permissions is often called the "PRAM zap of the 21'st century" and I agree. But just as a PRAM zap could fix a no-video issue, Repair Permissions can also help sometimes.

|
Back To Basics vol 2
Just so's I don't ever forget this again. To set up SSH without passwords:
mkdir ~/.ssh
ssh-keygen -t rsa
scp ~/.ssh/id_rsa.pub me@server:~/me/.ssh/authorized_keys2

man ssh

|
A Tribute To Michael Ransom
http://growingontrees.com

|
Creative Workflow Hacks
Ainult power-useritele! ;)

|
Localtime
For some weird reason this gets set incorrectly sometimes, so this helps:
sudo ln -s /usr/share/zoneinfo/EET /etc/localtime

|
Resizing FileVault Disk Images
After installing a bigger drive:

1) Log in as another admin user
2) cd /Users/filevaultuser
3) hdiutil resize -size 1t filevaultuser.sparseimage
4) Give *filevaultusers* password

|
Secure Subversion 1.3 w/ Apache 2.2 & XCode 2
http://developer.apple.com/tools/subversionxcode.html

>./configure --prefix=/usr/local --mandir=/usr/local/share/man --with-ssl --with-apxs=/usr/local/apache2/bin/apxs --with-zlib --without-berkeley-d 

> httpd.conf
## SVN
LoadModule dav_svn_module modules/mod_dav_svn.so
LoadModule authz_svn_module modules/mod_authz_svn.so

WebSVN:
include/config.inc
> nano include/setup.inc > languages/english.inc

> mkdir /usr/local/subversion/repos
> sudo svnadmin create /usr/local/subversion/repos
> mkdir branches tags trunk; mv MyProject/* trunk
> svn import MyProject file:///usr/local/subversion/repos
> chown -R www:www /usr/local/subversion/repos


Machine B
> svn checkout http://host/ project


Authentication
> htpasswd -cm /path/to/htpasswd/file user 
> nano -w httpd.conf

DAV svn
SVNPath /path/to/repos
AuthType Basic
AuthName "Subversion repository"
AuthUserFile /path/to/htpasswd/file

Require valid-user



XCode:
SCM Config > Subversion > /usr/local/bin/subversion --username user --password pw

http://www.alajaam.net/websvn

|