Jump to content

Firefox bookmarks and input history


Recommended Posts

Hello everybody,

 

I just got Alfred 2 today and I thought that the time has come to set an end to the scandalous situation that there is no access to Firefox bookmarks (screenshot):

 

https://github.com/nikipore/alfred-firefoxbookmarks

 

It's written in very basic Python. If anyone wants to join in, there are a couple of things one might do from here:

  • Quicksearch support
  • display Favicons - EDIT: done
  • better configurability (e.g. the place where places.db resides) - EDIT: done

 

EDIT: In the meantime, I've mashed up an IMHO quite useful and generic Python module which takes care of the nuts and bolts of the Alfred API (encoding issues, working directories according to the Workflow Best Practices, plist parsing, XML result compilation, ...). If you wish to use or improve it:

 

https://github.com/nikipore/alfred-python

 

Cheers

Jan

Edited by nikipore
Link to comment
  • 1 month later...

Hi and thanks for creating and sharing this workflow!

 

I still find it surprising Firefox bookmark indexing functionality isn't native, but I digress.

 

I can't seem to get this workflow to work. When I activate it with "ff", it does come up and says "Search Firefox Bookmarks", but any further typing results in an instant flip to the Alfred built-in default searches.

 

 

 

Any hints or ideas? I'm using FF 20.0. and OS X 10.8.3.

 

Thanks,

Mike

 

 

Link to comment
  • 4 months later...

Mike,

sorry for answering half a year later, but this forum's amazing activity in the birth phase of Alfred 2 workflows was just too much for me to follow, so I kind of pulled the plug. I'm on Mountain Lion too (10.8.5), and the workflow still works perfectly for me on FF 24. Are other Python workflows functioning? Where is your places.sqlite?

Cheers,

Jan

Link to comment

Thanks for getting back to me, Jan. Sadly, I had long since given up on using Alfred for my FF bookmarks, so I'm glad to hear from you!

 

I don't have any other python workflows in Alfred, so it could be python related.

 

When I run bookmarks.py by itself outside of Alfred, this is what I get:

/Application Support/Alfred 2/Alfred.alfredpreferences/workflows/user.workflow.7D2FE02B-9FB8-45B1-AE1F-DDFE468A3D4A python bookmarks.py "~/Library/Application Support/Firefox/Profiles/laurr8cc.default" "coke"
Traceback (most recent call last):
  File "bookmarks.py", line 69, in <module>
    alfred.write(alfred.xml(results(db, query), maxresults=_MAX_RESULTS))
  File "/Users/wagner/Library/Application Support/Alfred 2/Alfred.alfredpreferences/workflows/user.workflow.7D2FE02B-9FB8-45B1-AE1F-DDFE468A3D4A/alfred.py", line 84, in xml
    for item in itertools.islice(items, maxresults):
  File "bookmarks.py", line 36, in results
    for result in db.execute(sql(query)):
sqlite3.DatabaseError: file is encrypted or is not a database

I can open and navigate my places.sqlite database with sqlite3 cli tool.

 

Thanks,

Mike

Edited by wagnerone
Link to comment

Would you please temporarily replace the last block by the code below (the second and third lines have been inserted) and check /tmp/alfred.txt whether your places.sqlite file is identified correctly and exists?
 

(profile, query) = alfred.args()
import os
open('/tmp/alfred.txt', 'w').write('profile=%s\nplaces=%s\nexists=%s' % (profile, places(profile), os.access(places(profile), os.R_OK)))
db = sqlite3.connect(places(profile))
alfred.write(alfred.xml(results(db, query), maxresults=_MAX_RESULTS))
Link to comment

I did as you requested and here is the contents of /tmp/alfred.txt.

profile=~/Library/Application Support/Firefox/Profiles/*.default
places=/Users/wagner/Library/Application Support/Firefox/Profiles/laurr8cc.default/places.sqlite

I recalled I installed a version of python when I took a python course at one point. I compared my version against a fresh install of 10.8 and found I had 2.7.1 and the fresh install had 10.7.2. Following instructions on python.org, I removed the now outdated and non-stock 2.7.1 version and confirmed I am back to stock. When I run python bookmarks.py as i did before doing this, I get the following, different output.

python bookmarks.py "~/Library/Application Support/Firefox/Profiles/laurr8cc.default" "coke"
Traceback (most recent call last):
  File "bookmarks.py", line 71, in <module>
    alfred.write(alfred.xml(results(db, query), maxresults=_MAX_RESULTS))
  File "/Users/wagner/Library/Application Support/Alfred 2/Alfred.alfredpreferences/workflows/user.workflow.7D2FE02B-9FB8-45B1-AE1F-DDFE468A3D4A/alfred.py", line 84, in xml
    for item in itertools.islice(items, maxresults):
  File "bookmarks.py", line 41, in results
    yield alfred.Item({u'uid': alfred.uid(uid), u'arg': url}, title, url, icon(db, faviconid))
  File "bookmarks.py", line 20, in icon
    data = db.execute(u'select data from moz_favicons where id=%d' % faviconid).fetchone()[0]
TypeError: 'NoneType' object is not subscriptable
Link to comment

Please replace the icon method as shown below. This should catch your error. Please let me know if that helps; I will commit that patch to git, then.

def icon(db, faviconid):
    if not faviconid:
        return
    data = db.execute(u'select data from moz_favicons where id=%d' % faviconid).fetchone()
    if not data:
        return
    icon = os.path.join(_CACHE, 'icon-%d.png' % faviconid)
    if (not os.path.exists(icon)) or ((time.time() - os.path.getmtime(icon)) > _CACHE_EXPIRY):
        open(icon, 'wb').write(data[0])
    return icon
Link to comment

Thank you. That did catch the error and the plug-in is now operating!

 

However, I'm getting unexpected results.

 

Example - when I search for a known and pretty unique bookmark string "mameworld", I get a list of matches. One of them is indeed a "mameworld" bookmarks, but the rest don't have that string anywhere in them.

 

If I then search for "mame", I get a long list returned, but the string "mame" is not in that output.

Link to comment
  • 4 months later...

Hi there,

 

I also tried to run the plugin without success. I have the same problem as mentioned above :

 

I can't seem to get this workflow to work. When I activate it with "ff", it does come up and says "Search Firefox Bookmarks", but any further typing results in an instant flip to the Alfred built-in default searches.

 

So I run in terminal

PROFILE="~/Library/Application Support/Firefox/Profiles/*.default"
python bookmarks.py "${PROFILE}" "{university}"

but got nothing (no error message).

 

Then I followed this:

 

 

Would you please temporarily replace the last block by the code below (the second and third lines have been inserted) and check /tmp/alfred.txt whether your places.sqlite file is identified correctly and exists?
 

(profile, query) = alfred.args()
import os
open('/tmp/alfred.txt', 'w').write('profile=%s\nplaces=%s\nexists=%s' % (profile, places(profile), os.access(places(profile), os.R_OK)))
db = sqlite3.connect(places(profile))
alfred.write(alfred.xml(results(db, query), maxresults=_MAX_RESULTS))

and got the following content for /temp/alfred.txt :

profile=~/Library/Application Support/Firefox/Profiles/*.default
places=/Users/my_username/Library/Application Support/Firefox/Profiles/my_profile.default/places.sqlite
exists=True

For your information, I'm running Snow Leopard 10.6.8 on a macbook and using Homebrew's Python 2.7.6.

 

I got the Alfred Powerpack quite recently and searching through my Firefox bookmarks was a big reason for that... so any help would be warmly welcome. Thanks in advance.

Link to comment

@clenden

 

I'd suggest to drill into the cause of your problem by debugging intermediary results with either one of the two methods:

  • print statements (only works on the command line)
  • writing to a temporary file (see above how to do that)

The most likely cause I can think of is that the places.sqlite you are scanning is not the one associated to the Firefox profile you are actually using. What FF version are you on, btw?

Link to comment

@nikipore

 

Last time I didn't remove the curly braces around PROFILE and query while testing bookmarks.py in Terminal, so that couldn't work obviously. Now with

PROFILE="~/Library/Application Support/Firefox/Profiles/*.default"
python bookmarks.py "$PROFILE" "Tiger"

I get this in Terminal :

<items><item arg="http://en.wikipedia.org/wiki/Siberian_Tiger" uid="nikipore.firefoxbookmarks-25933"><title>Siberian Tiger</title><subtitle>http://en.wikipedia.org/wiki/Siberian_Tiger</subtitle><icon>/Users/my_username/Library/Caches/com.runningwithcrayons.Alfred-2/Workflow Data/nikipore.firefoxbookmarks/icon-31.png</icon></item><item arg="http://animals.nationalgeographic.com/animals/photos/tigers/" uid="nikipore.firefoxbookmarks-25945"><title>Tiger Pictures</title><subtitle>http://animals.nationalgeographic.com/animals/photos/tigers/</subtitle><icon>/Users/my_username/Library/Caches/com.runningwithcrayons.Alfred-2/Workflow Data/nikipore.firefoxbookmarks/icon-5332.png</icon></item></items>

It does make sense since I've got exactly those two bookmarks with the "tiger" keyword in my FF.

 

So your script did find my Firefox profile and the scanned places.sqlite is the one associated with my profile.

 

Still, no result in the Alfred bar. I type ff + Enter, then for any key  I get "Scanning" displayed one split second but the Alfred built-in default searches show up immediately.

 

Something wrong with my Alfred 2 app ? I just double clicked the Firefox Bookmarks.alfredworkflow to install the plugin. Do I need to do something else in my Alfred Preferences to make it work ? I'm a newbie with workflows in Alfred so I might be missing something trivial.

Link to comment

Awesome ! I was finally able to make it work. Here is my process to figure it out so folks who get the same problem will likely waste less time than I did.

 

First I ran into the the same kind of problem with another workflow using Python scripts (it was ZotQuery).

By running ZotQurey in the Alfred bar, I was given a useful Python Attribute Error message though. I was told that the collections Python module had no attribute OrderedDict.

Then I found out that OrderedDict is a Python 2.7 new attribute of collections. So Alfred was using the default Apple Snow Leopard Python 2.6 (/usr/bin/python)  instead of my Homebrew Python 2.7.6 (/usr/local/bin/python).

 

That was tricky cause I'd already set my PATH to look first for /usr/local/bin and the bash command which python kept telling me that my default Python was the Homebrew /usr/local/bin/python as expected.

I eventually found out Alfred isn't loading my local PATH. It uses the Apple-provided /usr/bin/python.

So I had no choice than to replace my Apple-provided Python, which is something that people are usually warned against. If you're a Snow Leopard user that wanna get it done properly (hopefully), I would suggest you follow this link http://wolfpaulus.com/jounal/mac/installing_python_osx/.

(Just in case, do a "brew uninstall python" and a "brew install python" to make sure that all goes well later on for your Homebrew's Python)

 

Now that my /usr/bin/python is a symlink of python 2.7.6, all my Alfred workflows work like a charm.

 

@nikipore : Your workflow already made my life easier ! Thanks so much for your job.

Edited by clenden
Link to comment
  • 2 years later...
On 26/02/2014 at 6:46 PM, lendenmc said:

which is something that people are usually warned against.

 

There's a very good reason for that. Namely, it breaks your operating system. The people saying that know what they're talking about. If you really want to break your system, by all means go ahead, but please don't go telling other people to do the same silly thing.

 

Homebrew Python does not come with the same libraries installed as the system Python, so there's a very good chance you'll break other software. Your changes will also be overwritten when you update the OS.

 

If you want to use a different Python, edit the workflow instead of — quite literally — breaking your OS X installation.

 

It's absolutely trivial to fix. All you have to do is open the Script Filter in the workflow and change "python bookmarks.py…" to "/usr/local/bin/python bookmarks.py…"

 

If you'd just asked, anyone who knows anything about Python could have told you that. Instead, you go and start overwriting parts of your operating system and then tell other people to do the same thing. Not the smartest move, tbh.

 

If I were you, I'd go an find my Snow Leopard install media and repair the system. There's a fair chance you broke something else "fixing" the workflow.

Edited by deanishe
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...