Jump to content

How do I dynamically add keywords?

Recommended Posts

Is it possible to have a workflow/plugin programmatically dynamically add/remove keywords at runtime?  I'd like to code up a workflow that allows me to specify keywords to URLs in a text file.  For example, I have a text file calls "links.txt" where I can edit and add keyword,url combinations, like a line with "gmail,http://gmail.com" and my plugin/workflow will monitor that file and provide the first word as the keyword.  This way I only need to edit the text file to add/remove URL keywords.  I'll later expand the idea to run scripts by keyword as well. 


So far I've only seen workflows or examples with a static set of keywords.  Any points will help, thank you!


p.s. bonus for pointing to any code examples online!  Python or Ruby = +++ points  =P

Link to comment

Here you go. My Fuzzy Folders workflow that dynamically updates its own keywords. Written in Python.


The source code is on GitHub.


The relevant stuff is at the bottom of the ff.py file. You're basically rewriting parts of info.plist. A few things that came up while writing it:


  1. You have to specify the vertical offset of each keyword entry in info.plist or they'll all be piled on top of one another in the UI.
  2. Keep your keyword-URL combinations in a settings file outside of the workflow directory: info.plist gets overwritten when a workflow is updated. You'll want some type of automatic and/or manual update function for this case (just checking to see if your settings file has changed won't trigger an update if the workflow has been updated).
  3. Alfred takes a few seconds to notice that a workflow has been externally updated.
  4. You'll want to hardcode the UUID of any non-auto-generated keywords in your script, so you don't accidentally delete them during an update, too.
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...