On Nov 7, 2011, at 3:16 PM, Patrick Robertson wrote:

> * Rob's done a bit of work cleaning up mnemonics, he'll probably have a good 
> idea where the things are stored.
> * He may also be able to send over a script that can 'clean up' your 
> mnemonics.

The script makes up for a previous bug as described in the fix.

https://github.com/quicksilver/Quicksilver/pull/446

It’ll remove useless entries [potentially] speeding up the matching process. 
We’ve talked about including the script in a couple of Quicksilver releases and 
having it run in the background, but I’m not sure of the best way to handle 
that.

Feel free to run it manually for now (`python clean_mnemonics.py` in the 
Terminal). Your original file will be copied to the Desktop. Hang onto it in 
case you run into any problems. It’ll quit Quicksilver for you and restart it 
after, so leave it up and running.

-- 
Rob McBroom
<http://www.skurfer.com/>


-- 
Rob McBroom
<http://www.skurfer.com/>

import os
import sys
import plistlib
from shutil import copy
from commands import getstatusoutput

qsquit = getstatusoutput('osascript -e \'tell application "Quicksilver" to quit\'')
if qsquit[0] > 0:
    print 'Unable to quit Quicksilver'
    sys.exit(qsquit[0])

home = os.getenv('HOME', '')
plist_path = home + '/Library/Application Support/Quicksilver/Mnemonics.plist'
# plist_path = home + '/Desktop/Mnemonics.plist'
## back up the original to ~/Desktop if this is the first run
if not os.path.exists(home + '/Desktop/Mnemonics.plist'):
    copy(plist_path, home + '/Desktop/')

mnemonics = plistlib.readPlist(plist_path)
cleaned = {
    'abbreviation': {},
    'implied': {},
}

## check these paths for files that no longer exist
prefixes = [
    home,
    '/Applications',
]

## by abbrevation
for (abbr, vals) in mnemonics['abbreviation'].items():
    ## get rid of empty abbreviations
    if abbr == '': continue
    ## get single-object items
    singles = []
    for v in vals:
        if ' /' in v: continue
        if True in [v.startswith(pf) for pf in prefixes]:
            if not os.path.exists(v): continue
        singles.append(v)
    if len(singles) > 0:
        cleaned['abbreviation'][abbr] = singles

## by object
for (qso, abbrs) in mnemonics['implied'].items():
    ## remove references to multiple objects
    if ' /' in qso: continue
    ## remove references to files that don't exist
    ## (but only from common locations on the mounted volume)
    if True in [qso.startswith(pf) for pf in prefixes]:
        if not os.path.exists(qso): continue
    ## remove empty abbreviations
    for (abb, count) in abbrs.items():
        if abb == '': continue
        if cleaned['implied'].has_key(qso):
            cleaned['implied'][qso][abb] = count
        else:
            cleaned['implied'][qso] = {}
            cleaned['implied'][qso][abb] = count

# plistlib.writePlist(cleaned, home + '/Desktop/clean.plist')
plistlib.writePlist(cleaned, plist_path)
relaunch = getstatusoutput('open -a Quicksilver')

Reply via email to