OS X URL handler to open links to local files

·

Warning: don't use the actual protocol 'local' as described here. Make up your own protocol name using random letters that no-one can guess, as otherwise it could allow anyone to run local files on your computer.

  1. Use Script Editor to save this script as an Application Bundle (no startup screen):
    
    on open location localURL
        
        set oldDelims to AppleScript's text item delimiters
        set AppleScript's text item delimiters to "local://"
        set thePath to item 2 of the text items of localURL
        set AppleScript's text item delimiters to oldDelims
        
        tell application "System Events"
            open ((POSIX file thePath) as string)
        end tell
        
    end open location
    
  2. Use the method described here and here to set CFBundleSignature to LOCL and add
    
    <key>CFBundleURLTypes</key>
    <array>
        <dict>
            <key>CFBundleURLName</key>
            <string>Local File</string>
            <key>CFBundleURLSchemes</key>
            <array>
                <string>local</string>
            </array>
        </dict>
    </array>
    <key>NSUIElement</key>
    <true/>
    
    to the application bundle's Info.plist file, then change the PkgInfo file to contain APPLLOCL
  3. Use the More Internet preference pane to add 'local' as a new protocol and choose the new application as the handler.
  4. Make hyperlinks in the form local:///path/to/your/local/folder. Clicking those links should then open that file or folder.

Why is this useful? I'm using it with a private Wordpress weblog, where each category is linked to a local folder containing all the files related to that category.