Jump to content
noahcoad

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

Share this post


Link to post

You should be able to do it by editing the Info.plist file, inside the workflow. Take a look at dash: they have a workflow that does something similar. They dynamically add and remove Script Filters depending on the docsets you download in the app.

Share this post


Link to post

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

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...