MacTechNotes

Tuesday, October 11, 2005

Spotlight Control

Overview
Spotlight currently has only minimal configuration options: result types to show and their order, and a list of folders not to search. Other folders can be searched which aren't by default, but this option is not exposed through System Preferences.
There are currently three property list files (.plist) which control Spotlight: _IndexPolicy.plist, _exclusions.plist, and _rules.plist.
These files reside in the directory named .Spotlight-V100 on the volume in question. This directory is readable only by root for the primary boot volume, so you'll need to be able to use sudo even to look at them. These, unlike application preference files, are still in plain text so can be viewed easily.

Read on for more detail


_IndexPolicy.plist
This file contains policy information, which is stored in just one key: Policy.
I've currently only figured out two possible settings for this so far:

  • Enabled
    Setting this to a 5 means Spotlight is enabled for the given volume

  • Disabled
    Setting this to a 3 means Spotlight is disabled for the given volume



Enabled example (this is how it should appear by default in most cases):

<?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>Policy</key>
<integer>5</integer>
</dict>
</plist>


_exclusions.plist
This contains information about which folders not to search, which are listed in one key: EXCLUSIONS. The value for this is an array of strings, each string being a path to exclude from Spotlight searching.

Example including several paths to not search (in this case, the folders are the DarwinPorts build directory, the system temporary directory, and my user temporary directory):

<?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>EXCLUSIONS</key>
<array>
<string>/opt/local/var/db/dports/build</string>
<string>/private/tmp</string>
<string>/Users/blb/tmp</string>
</array>
</dict>
</plist>


_rules.plist
_rules.plist includes both paths to include and to exclude (which makes it a bit redundant with _exclusions.plist). The paths to include are only for cases where Spotlight would otherwise ignore them (it has several paths which it is hardcoded to ignore, see the Known Exclusions section below).
When adding a path which is otherwise skipped, simply updating _rules.plist will not cause anything to happen. Once _rules.plist is as you like, you'll first need to restart mds by stopping it:

sudo killall mds

It will restart automatically. Then, you need to tell mds to import each new path:

sudo mdimport /path/to/files

This will then cause mds to import everything under /path/to/files. If there are many files, it could take some time. You'll need to do this for each new path.
This file can contain several keys:

  • EXCLUDE
    An array of strings, each string being a path to exclude (like EXCLUSIONS in _exclusions.plist).

  • INCLUDE
    Another array of strings, this time being paths to specifically search (to override the hardcoded exclusion list).

  • NOTE
    This is a note, read it and move on.


There are several other values which may be keys. The functionality of each has not yet been found, but some may be obvious (the *_USER ones at least): INCLUDE_USER, EXCLUDE_USER, INCLUDE_BOOTABLE, EXCLUDE_BOOTABLE, INCLUDE_GENERAL, EXCLUDE_GENERAL, CLASSIC_LOCATIONS.

My _rules.plist which gets the *nix path of /etc (AKA /private/etc on Mac OS X) and the whole suite of Xcode documentation:

<?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>EXCLUDE</key>
<array/>
<key>INCLUDE</key>
<array>
<string>/private/etc</string>
<string>/Developer/ADC Reference Library</string>
</array>
<key>NOTE<key>
<string>Specify paths to include or exclude, preceeding rules which target user-homes with ~/</string>
</dict>
</plist>


Known Exclusions
These are the paths I know to be excluded by default by Spotlight (there may be others I've missed):

/Developer/ADC Reference Library
/Developer/Documentation
/Previous Systems.localized
/Network
/Volumes
/private
/tmp
/var
/etc
/usr
/bin
/sbin
/dev
/automount
/cores
/mach.sym
/iPod_Control
/System Folder
/Classic
/System/System Folder
/Classic System Folder 9.2.2

Note the *nix paths are included, so don't expect to use Spotlight to search man pages or HTML docs which can be found in /usr/share/*.


continues...

Sunday, October 02, 2005

Controlling WebKit and Safari through Preferences

Overview
Mac OS X has a centralized preferences system (stuff in ~/Library/Preferences) which, for some apps, contains hidden settings. Some of these can be quite useful, interesting, or annoying. This is coverage of such settings for Safari and the underlying WebKit.
First, a warning. None of these settings are in any way guaranteed to work after this is written, nor are they safe from blowing up your keyboard when entered. If you test any of these, be sure to keep track of which, especially when OS/Safari/WebKit updates come from Apple, as otherwise very strange things could happen.
I'm not going to cover how to change defaults (hint, Terminal's defaults or Property List Editor) as that's covered nicely elsewhere. All these should be done only to com.apple.Safari (at least initially) so you don't break other apps which use the system's WebKit.
Except for CustomUserAgent, the Safari list does not cover items which can be set through the Debug menu (but does include enabling said menu). This also does not cover basic AppKit-level preferences (those beginning with NS, like NSNavLastRootDirectory).

Read on for more detail


WebKit Preferences
WebKit preferences can be set in Safari's preferences to avoid affecting other WebKit-based applications. They can also be set in those apps' preferences if needed, or even in the global domain to affect everything. To be safe, start off just changing Safari's prefs.
If you want the definitive reference for WebKit preferences (and other things WebKit), please check the source.

  • WebKitHistoryItemLimit (number)
    This (which is by default 1000) sets how much history is remembered and is a simple page count.

  • WebKitHistoryAgeInDaysLimit (number)
    The number of days an item on the history list lives, after which it is removed (defaults to 7). This plus WebKitHistoryItemLimit allow you to control the history list either with a simple count, or age. To be safe with the age (if you do lots of browsing), you may want to increase the item limit so it doesn't kick in before the age limit.

  • WebIconDatabaseEnabled (boolean)
    Whether storing web site icons (favicon.ico files) are kept (defaults to YES). When enabled, see WebIconDatabaseDirectoryDefaultsKey for where they go.

  • WebIconDatabaseDirectoryDefaultsKey (string)
    When web site icons are enabled (via WebIconDatabaseEnabled), this specifies where the database is located. WebKit sets this to ~/Library/Icons, but Safari changes it to an app specific ~/Library/Safari/Icons.

  • BufferTextDrawing (boolean)
    Enables some form of text drawing buffering, which may or may not be fully implemented yet (currently defaults to NO).

  • WebKitOmitPDFSupport (boolean)
    Use to disable handling PDF within WebKit (defaults to NO, or support PDF). When PDF is handled by WebKit, it displays the PDF in the view where HTML shows (eg, the normal display area in Safari). When not handled, Safari simply downloads the PDF.

  • WebKitLogLevel (string)
    This is a mask value, and is not enabled in Safari.

  • WebKitPageCacheSizePreferenceKey (number)
    Specifies the size of the page cache; first thing to note is that it is somewhat dependent on the amount of memory on the machine (1G or more of memory, this value is used; between 0.5G and 1G, and one less is used; under 0.5G and two less is used). This is the page cache, not what's stored on disk, so it's quite small (default is 3).

  • WebKitObjectCacheSizePreferenceKey (number)
    Indicates the size of the object cache; like WebKitPageCacheSizePreferenceKey, this is dependent on system memory (1G or more multiplies this by four, 0.5G by two, and less does no multiplication). Default is 8388608, which is 8M.

  • WebKitShouldPrintBackgroundsPreferenceKey (boolean)
    When YES (defaults to NO), for any page which uses a background image, will include that image when printing.

  • WebKitTextAreasAreResizable (boolean)
    Appears to be unused so far (defaults to NO).

  • WebKitAllowAnimatedImagesPreferenceKey (boolean)
    Appears to be unused so far (defaults to YES).

  • WebKitAllowAnimatedImageLoopingPreferenceKey (boolean)
    Appears to be unused so far (defaults to YES).

  • WebKitBackForwardCacheExpirationIntervalKey (number)
    How long a cached page can be used when going back/forward through history (defaults to 1800 seconds).

  • WebKitRespectStandardStyleKeyEquivalents (boolean)
    When YES, allows certain keyboard shortcuts to turn on/off certain styles (like bold and italic). NO is WebKit's default, but Safari sets it to YES.

  • WebKitShowsURLsInToolTips (boolean)
    If set to YES, shows a link's URL in a tooltip; default is NO.

  • WebKitPDFDisplayMode (number)
    Should be the style used for displaying PDFs, but it seems to have no effect.
    This and WebKitPDFScaleFactor can be set (for the current session only) by Ctrl-/right-clicking when viewing a PDF and selecting the appropriate setting.

  • WebKitPDFScaleFactor (number)
    Should set the scaling used when displaying PDFs, but seems ignored.



Safari Preferences
These are for Safari only so will not do much of anything for other WebKit-based applications.

  • IncludeDebugMenu (boolean)
    When YES, includes the Debug menu (to modify some of Safari's behaviour). Default is NO.

  • Log (boolean)
    If set to YES, logs some syndication information to stderr (console log if you run Safari in the normal ways). Default is NO.

  • Log.SPI (boolean)
    Logs more detailed syndication information when YES (also to stderr). Defaults to NO

  • CacheDirectory (string)
    Where Safari places its on-disk cache files. Default is ~/Library/Caches/Safari. Note, in my testing, when changing this, Safari will create both the new location and the default, but not actually write anything in either location.

  • DebugShowBuildNumberInWindowTitles (boolean)
    When YES, adds the current build number (eg, 'v412.5') in window titles.

  • CustomUserAgent (string)
    Allows control over what Safari sends as its user agent string back to web servers; default is "Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en-us) AppleWebKit/412.7 (KHTML, like Gecko) Safari/412.5" as of Safari 2.0.1/412.5. The Debug menu allows you to set some canned values for this, but setting it through preferences lets you use any old string you wish.

  • BackForwardListSizeLimit (number)
    Controls the size of the back/forward history list; defaults to 100. Do not set to anything under 100, or Safari will become confused, except for 0 which disables the back button altogether. Values over 100 are acceptable.



continues...