Select Page

Spotlight on the commandline

As pointed out in the excellent arstechnica review Apple chose not to expose a fraction of the usefulness of Spotlight to the GUI, I suspect within days there will be a Shareware Spotlight power users GUI out that bridge this gap, I can only wish.
For now, if you want to do some kick arse queries you need to use the command line and it really is very powerful. I scp’d a couple of my photos onto the apple hard drive and now I can do really nice queries over my photos like this one:

[rip@temptation]% mdfind 'kMDItemAcquisitionMake == "nikon*"c && \
kMDItemExposureTimeSeconds >= 1'
/Users/rip/Pictures/book/hms-belfast.jpg
/Users/rip/Pictures/book/london-eye.jpg
/Users/rip/Pictures/book/albert-bridge.jpg

The above bit will find all the photos on my drive shot by a Nikon camera with a exposure time of more than 1 second.
This is pretty kewl, and a wealth of meta data gets stored by default for images, this is a dump of one of the above photos:

[rip@temptation]% mdls /Users/rip/Pictures/book/albert-bridge.jpg
/Users/rip/Pictures/book/albert-bridge.jpg -------------
kMDItemAcquisitionMake         = "NIKON CORPORATION"
kMDItemAcquisitionModel        = "NIKON D70"
kMDItemAperture                = 8.33985
kMDItemAttributeChangeDate     = 2005-04-30 00:54:33 +0100
kMDItemBitsPerSample           = 32
kMDItemColorSpace              = "RGB"
kMDItemContentCreationDate     = 2005-04-24 00:40:51 +0100
kMDItemContentModificationDate = 2005-04-24 00:40:51 +0100
kMDItemContentType             = "public.jpeg"
kMDItemContentTypeTree         = ("public.jpeg", "public.image", \
"public.data","public.item", "public.content")
kMDItemDisplayName             = "albert-bridge.jpg"
kMDItemExposureTimeSeconds     = 5
kMDItemFlashOnOff              = 0
kMDItemFocalLength             = 18
kMDItemFSContentChangeDate     = 2005-04-24 00:40:51 +0100
kMDItemFSCreationDate          = 2005-04-24 00:40:51 +0100
kMDItemFSCreatorCode           = 0
kMDItemFSFinderFlags           = 0
kMDItemFSInvisible             = 0
kMDItemFSLabel                 = 0
kMDItemFSName                  = "albert-bridge.jpg"
kMDItemFSNodeCount             = 0
kMDItemFSOwnerGroupID          = 501
kMDItemFSOwnerUserID           = 501
kMDItemFSSize                  = 1072065
kMDItemFSTypeCode              = 0
kMDItemHasAlphaChannel         = 0
kMDItemID                      = 455102
kMDItemISOSpeed                = -2.321928
kMDItemKind                    = "JPEG Image"
kMDItemLastUsedDate            = 2005-04-24 00:40:51 +0100
kMDItemOrientation             = 0
kMDItemPixelHeight             = 1555
kMDItemPixelWidth              = 2481
kMDItemProfileName             = "sRGB IEC61966-2.1"
kMDItemRedEyeOnOff             = 0
kMDItemResolutionHeightDPI     = 300
kMDItemResolutionWidthDPI      = 300
kMDItemUsedDates               = (2005-04-24 00:40:51 +0100)

All isn’t perfect though, notice the kMDItemISOSpeed? It’s blatantly wrong, so thats really a pain.
Here is a nifty little show off trick with mdfind, the GUI has the nice auto updating of results going which is obviously difficult to show in the command line world, but it has something at least.
To set this up do a query that will match files – one that you can easily add more matches to.

[rip@temptation]% mdfind -live apple
<snip>
Users/rip/Library/Preferences/com.apple.recentitems.plist
/Users/rip/Library/Preferences/com.apple.dashboard.plist
/Users/rip/Library/Preferences/com.apple.Syndication.plist
/Users/rip/Library/Preferences/com.apple.Safari.plist
[Type ctrl-C to exit]
Now here comes the magic, create some files that match in another term or through finder.
[rip@temptation]% mkdir apple
[rip@temptation]% rmdir apple

If you paid attention to the other window you will see it updated on the fly like this:

Query update: 378 matches
Query update: 377 matches

And to see just how deep the indexing goes, if you have Photoshop on your machine, create a new file and put some text on a image, something that will match your query. You will see Spotlight finds even this text on an image.

Spotlight not finding new files?

A friend installed his new Tiger today and found that only the files that was on his drives at first boot is in the spotlight database, nothing new was being added.
At first glance everything looked fine, but this very simple test will confirm if spotlight is working or not:

[rip@temptation]% touch test
[rip@temptation]% mdls test
test -------------
kMDItemAttributeChangeDate = 140116-07-24 20:14:56 +0000
kMDItemFSContentChangeDate = 2005-04-30 00:10:37 +0100
kMDItemFSCreationDate      = 2005-04-30 00:10:37 +0100
kMDItemFSCreatorCode       = 0
kMDItemFSFinderFlags       = 0
kMDItemFSInvisible         = 0
kMDItemFSLabel             = 0
kMDItemFSName              = "test"
kMDItemFSNodeCount         = 0
kMDItemFSOwnerGroupID      = 501
kMDItemFSOwnerUserID       = 501
kMDItemFSSize              = 0
kMDItemFSTypeCode          = 0
kMDItemID                  = 531254
kMDItemLastUsedDate        = 2005-04-29 23:10:37 +0100
kMDItemUsedDates           = (2005-04-29 23:10:37 +0100)

This creates a new file and then asks spotlight to list the metadata for this file, if spotlight isn’t indexing then nothing will be displayed after the second command. This was the case for this user.
Spotlight has a command line control tool called mdutil(1) that can start, stop and display current indexing state among other things, I turned indexing off and back on for the / volume on his machine and all was fine.

[rip@temptation]% sudo mdutil -i off /
Password:
/:
Indexing disabled for volume.
[rip@temptation]% sudo mdutil -i on /
/:
Indexing enabled for volume.

After that the simple test above should work. Note though that the new files may not immediately show up in search results since its likely that your machine may be now importing quite a few files into the datbase in a low priority background task, but things should be back to normal eventually.
In some cases though it seems not even this kicks the bugger back to life. So it is time to get a bit tough on it, so you can completely whipe the spotlight data store for a volume which will cause a immediate resync.

$ mdutil -E /

After this your spotlight will not work for a while, it will be like right after a fresh install, once it is done rebuilding and your spotlight icon lets you run searches it seems a reboot is in order, when you are back from the reboot it should all be good.
A quick test is to run a search for something in the spotlight GUI, click on ‘Show All’ and while this window is open make a folder or something that will match your query in a terminal, your spotlight results should dynamically update to include the new match.
UPDATE: You can also force a re-index by adding your whole harddrive to the Spotlight ‘private’ list and then removing it from the list after a while. Using this method you wont need a reboot or anything, plus it’s reachable by the GUI.

OS X Keyboard Short Cuts

The first thing that I had to try and figure out when getting the Apple was the keyboard short cuts, my busted wrists situation makes me a total keyboard junky, I try not to touch the mouse at all. This is somewhere that Apple really needs a big slap on the head because its horrible.
For instance, to get to the Google search box in Safari is a 3 key hotkey combo, get real! Apple is not only creating todays funky hip yuppy look but they are creating a whole lot of jobs for unskilled labor of the future looking after people whose hands are completely destroyed from using this Operating System for years.
The idiocy of Safari shortcuts are somehow mitigated by the fact that you can create shortcuts for bookmarks, so I’ll create ^K shortcut to launch the Google bookmark, it’s lame but should work. For all the Safari shortcut goodness look here, it also mentions about bookmark hotkeys.
In general Apple’s approach to UI consistency is to make things as inconsistent as possible. Each app behaves differently, has different keyboard controls, looks differently etc.
For instance you have your Brushed Metal apps – think iTunes – apart from being ugly and bloated they let you drag the whole window around by grabbing onto any metal surface and dragging, thats quite nice. Then you have a completely different style for apps like the System Preference, TextEdit etc. Now with Tiger a new ‘Plastic’ look is appearing, specifically the Mail.app is now completely different from anything else that came before. Also the spotlight search box is completely inconsistent with the design of the rest of the desktop.
Mostly there is a feel of stuff being patched on. I remember outside the town I grew up there was a guy who always built onto his house. As I grew older so the house grew, but he always did in slightly different designs and colors and real soon it looked pretty screwed up, that’s pretty much the feeling I am starting to have about OS X and the applications coming from Apple, it’s as if they are still trying to find the right way, I just hope when they do find it they will make everything look and behave the same.
Any way, I digress, the point to this is, here is a doc with loads of OS X shortcuts, even covering useful things like how to avoid Startup Items from loading at boot time using obscure keyboard shortcuts (hold in shift during the progress bar! how intuitive). Don’t sue me when after using this for a few years you need someone to help you go to the toilet because your hands are useless.
UPDATE:I tried the Safari bookmark shortcut thing with mixed results, it just does not always work consistently. So after some more hunting through the menu’s I saw there is Edit -> Find -> Google Search …. as an option. This is great news because OS X lets you remap hotkeys in menu in the keyboard preference page. Details on that here. Now I have command-k as a hotkey for accessing the Google box and things are looking better.

OS X to Samba slow performance

I have been really annoyed at this iBook since it was very very slow to my Samba servers – around 200kb/sec – and no amount of fiddling the Samba could get it to go fast.
First I tested using my Windows machines to the Samba servers in question and they were very fast as you’d expect, the Apple just wasn’t fast at all. Today when I got to work for the first time in ages I noticed that accessing my RedHat Enterprise Samba server is fast, so tonight I upgraded my Samba’s at home to version 3 and that fixed it.
So if your OS X is performing slow to Samba servers, make sure you are on the 3 branch of Samba.
UPDATE: After this I was still having some issues, especially with very slow read performance.
I came across this post on macosxhints and figured I’d give it a try, sorted, reading and writing is much faster now.

OS X Virtual Desktop Software

Being that I only have a little 12″ iBook that can do 1024×768 and no more having virtual desktops is essential. This is something that even Microsoft give away for free with the Power Toys these days but not Apple, so you have to hunt around.
There are a number of options, 4 opernsource and maybe another 4 commercial that I found. Till today I used Desktop Manager, it is a opensource project and does what you want it to do it does however have some issues. Most annoyingly it interacts badly with Adium X, Adium developers claim that the Desktop Manager author has admitted to it being a bug in his software but has not yet fixed it. I was reluctant to move away from it since it has a nice global-hotkey run dialog that is very useful for launching apps without having to hunt around the ghastly Finder or Dock applications.
Today I switched to Virtue, it is nice and based on Desktop Manager but has some additional features and it integrates with the system alt-tab behavior to switch desktops to the one that the app you choose is on. It also supports more hotkeys for switching desktops and understands about keeping a specific program in all desktops.
What about hotkeys? Well I also invested the time in learning Quicksilver, there is no going back, it’s absolutely brilliant, but more on this later on.

GLTerm for OS X

The very first thing that annoyed me about the Apple was its default terminal. It’s crap, it really is, its the slowest terminal I have used in my life, it was as bad as using a modem again.
The problem is of course that it tries to render everything in amazing quality and do transparency and use true type fonts and all that, it pretty much made for a completely unusable experience for me.
I tried a couple of alternatives like iTerm and while feature wise they are better they were still slow.
Another MAJOR pain is the fact that unlike Unix terminals the OS X native one does not copy text when you select it, I am just too used to that feature to not have it – there may well be a button to select somewhere to enable it, but I have not found it. Regardless the default terminal is too slow.
So I came across a shareware tool called GLTerm. It uses OpenGL to do it’s rendering, at first this sounds like a stupid idea but it works, its really quick. Not as quick as Putty on my windows box but its fast enough and it supports copy on select which makes me happy, and $10 poorer.
UPDATE: The terminal in OS X is indeed much faster as pointed out below, it flies even on my old 800mhz ibook it still lacks copy-on-select though. Also you need to be aware that support from the GLTerm author is virtually non existent, you need to almost threaten the guy to get anything out of him, pity, it’s a good terminal.