When I upgraded to Snow Leopard a few months ago I found out quite quickly that locate didn’t work on the command line. Why locate is missing I don’t know, maybe find was supposed to replace it. But find doesn’t look deep enough into the system files to be useful for me. I finally got round to looking into the problem.

Using locate file.txt get’s us this:

WARNING: The locate database (/var/db/locate.database) does not exist.
To create the database, run the following command:

  sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.locate.plist

Please be aware that the database can take some time to generate; once
the database has been created, this message will no longer appear.

Ok. So it’s easy enough to run:

sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.locate.plist

But that didn’t do anything for me. Locate still threw the same error and top didn’t reveal any processes that appeared to be working overtime to build the database(*see below). Trying the launchctl load command again says it’s already loaded, and using start com.apple.locate via a launchctl daemon gets a start error:No such process message. So I opened /System/Library/LaunchDaemons/com.apple.locate.plist which revealed the task that actually does the work is locate.updatedb, so I tried:

sudo /usr/libexec/locate.updatedb

Which successfully built the database and locate now works. The one question remaining is wether the database will be updated automatically every Saturday at 3am as the plist file suggests. Maybe not, if the <key>Disabled</key><true/> in the plist is to be believed – so I’ve blindly switched it to false and am hoping for the best.

* I ran through this process again on a second machine, and it appears that I jumped the gun on this as I just left the machine be for half an hour and came back to it and the database worked.

Apache Bundle Upgrade

February 11th, 2008

The Apache bundle, which I originally contributed in the early days of TextMate, was due an upgrade. So I’ve made a few improvements…

Start, Stop, Restart and Graceful commands (⌘R)

These commands, which all target apachectl, are now bound to ⌘R under the source.apache-config scope which makes it more convenient to directly control httpd from TextMate.

As apachectl requires sudo privileges I used applescript for authentication. For reasons only known to Apple the password request dialog would launch but not get focus – leaving you to reach for the mouse to target the input field. Moving away from the keyboard is slow so this was something that really annoyed me. I’ve now switched to using the excellent tm_dialog system which makes things much smoother.

It is also possible to store your admin password in your Keychain, this is done by selecting the “Add to Keychain” toggle in the password request dialog box. I’m more than happy with the security implications of this as I’m fairly good at keeping my machines locked. If you do choose to do this then the command line security app will have access to the keychain item and is the only way someone could gain access.

Documentation (⌃H)

This now searches a documentation index file for the current word/selection then redirects or presents a list of matches as appropriate. If you appear to have the documentation installed locally then the script favours it over the apache website.

Open Include (⇧⌘D)

The language definition has been improved to add a scope for Includes. Using the key combination apple-shift-D on this scope opens the file referenced by the inlcude, or directory if it is wild carded.

Open Config… (⇧⌘C)

Previously there were various commands to open the apache.conf files these have now been consolidated into one command which searches the apache install directory, either /etc/apache2 or /private/etc/httpd depending on your version of OS X and the /users, /extra and /other subdirectories. All the conf files found are presented in pop-up from which one can be choosen to open.

Bundle Configuration

It is now possible to override the default bundle behaviour by setting the following environmental variables. TMAPACHEDIRECTORY, TMAPACHEACCESSLOG, TMAPACHEERRORLOG and TMAPACHEMANUAL_URI all allow the custom targeting of files and directories. See the bundle help for a detailed explanation.

I share one of my development machines with another flash developer and have run into a problem whereby the debug flash player was only available to the user who installed it. Trying to set more generous permissions on the plug-in didn’t work. So I simply changed the name of the plug-in by prefixing it with the installing users name then reinstalled it as second user. This leaves you with multiple instances of the flash player in Library/Internet Plug-Ins but as each user only has permission to use the player they installed no confusion arises.

The most recent debug player can be found here. An archive of debug players can be found here.

Using svnX via svn-ssh

February 5th, 2007

This is a relatively simple thing to do, and it’s really all about setting up shh rather than svn, but when you don’t quite understand what is happening it’s a little creepy having the authentication handled automatically. The shh authentication process uses a public / private key system which is explained nicely here.

To start you need ssh to use keys rather than passwords. This is because subversion needs to “transparently” authenticate each time you make a request. I hope I’m right in thinking that it opens a tunnel to the remote machine and invokes the service as a svnserve process there.

So, open a terminal window and type ssh-keygen -d to generate your public and private ssh keys. Hit return at each prompt to stick with the default options. You’ll end up with two files called iddsa.pub and iddsa in your pwd move the files to ~/.ssh/. Then you need to copy the contents of iddsa.pub to this file ~/.ssh/authorizedkeys on your remote machine ( the one hosting the subversion repository) – creating it if it doesn’t exist. You can append more than one public key to the authorizedkeys file if you’re connecting from more than one machine. If you have access to more than one user account on the the remote machine then you need to copy the key into each users authorizedkeys file. I used CyberDuck along with a sftp connection to get the onto the remote machine. You should then be able to login to the remote machine using username@server.org.

Once you’ve got the ssh connection verified it should be plain sailing with svnx. You’ll be able ot use your repository with the following

svn+ssh://username@domain.com/path/to/repository

I’ve just found this on the TextMate blog. It’s covering the same ssh key generation process, but using the command line completely, and describing how to set up ssh aliases to save a little bit of typing.

svn ignore

January 20th, 2007

How do you get subversion to ingnore certain files? It can be done globally or on a per directory basis.

For global ignores find your subversion config file. For me this was here ~/.subversion/config then edit the following line, here I’ve added *.tmproj to ignore any file which ends with .tmproj (the * being a reg exp for any prefix).

global-ignores = .o *.lo *.la ## .*.rej *.tmproj

To ingnore files on a per directory basis cd to the directory in question and use the following.

svn propset svn:ignore "*.cache" .

This will apply the ignore to the file or files specifed by the pattern. In this case all files ending with .cache. The trialing . applies the ignore to the current directory, but can be the path to any subversion directory. The command above creates a .svn/dir-props file with the following contents in the specified directory.

K 10 svn:ignore V 8 *.cache

END

Here’s a useful snippet to enable you to securely store passwords in OS X’s keychain and use them in a shell scripts.

#!/bin/bash

PASSWORD=`exec osascript <<EOF | tr "\r" "\n"
    
    (* 
     To use the Keychain to store the admin password then 
     
     Open /Applications/Utilities/Keychain Access.app
     Add a new keychain called "TM" 
     Add a Key with the name "test" and store your password in it.
     
     I'd recommend learning how keychains work then tailoring 
     the process to your security needs.
    *)

    tell application "Keychain Scripting"
        set myKeyChain to keychain "TM.keychain"
        set theKeyList to every key of myKeyChain
        set thePassword to ""
        repeat with x from 1 to (length of theKeyList)
            set theKey to item x of theKeyList
            if the name of theKey is "test" then
                set thePassword to password of theKey
                --exit repeat leaves us without 
                --a value returned to the shell script...
            end if
        end repeat
    end tell
    
EOF`

echo "$PASSWORD"

exit 0;

Download:

Update: As of Leopard it is now possible to do this via the command line tool security

That Dictionary File,

January 11th, 2007

the one i’m always forgetting where it hides, with the 234,936 english words in, is here

/usr/share/dict/web2

as the readme says “it makes a dandy ‘grep’ vicitim”. Want a random word? perl -e 'rand($.) < 1 && ($line = $_) while <>; print $line' \ /usr/share/dict/web2

Change “Welcome to Darwin!”

January 11th, 2007

Here’s how to change the “Welcome to Darwin!” message when you open a new terminal. Simply open:

/etc/motd

and change the contents to whatever you like. I favour “Welcome to Hell!”

Update: As of Leopard you may find that the motd (Message of the Day) file no longer exists. If this is the case then you just need to create it. The contents will then be displayed each time you open a new Terminal window.

I wrote the following shell script a while back for use with TextMate as part of my build process. TextMate’s great as it easily allows you to bind scripts to custom commands (and key combinations). However you’d easily be able to adapt it to your set up. It will allow you to cleanly change all the flash players available for OS X, as well as being able to Uninstall the player, and optionally restart open browsers (FireFox and Safari) afterwards.

You’ll need to download the players, install and move the files into archived folders the contents of which the script will copy to the default internet plug-ins folder. It shouldn’t be too difficult to work out how this happens and alter the script for your needs.

Download the script here

To install the FP 7.0.14 without restarting any open broswers:

changePlayer.sh 7.0.14 false

To uninstall the flash player:

changePlayer.sh uninstallflashplayer

To install FP 6.0.49, restarting open browsers:

changePlayer.sh 6.0.49

If there’s anyone out there using TextMate and would like a the above wrapped up in a bundle then please email me and I’ll send a copy over.

Recursively remove .svn files

December 16th, 2005

Here’s a quick shell script to recursively remove all the the .svn files starting in the current directory and working down.

find . -type f -name "*.svn" -exec rm '{}' \; -print

Change .svn to look for different types.

Fork me on GitHub