noahcoad Posted July 18, 2014 Share Posted July 18, 2014 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
vitor Posted July 18, 2014 Share Posted July 18, 2014 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. noahcoad 1 Link to comment
deanishe Posted July 20, 2014 Share Posted July 20, 2014 (edited) 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: 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. 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). Alfred takes a few seconds to notice that a workflow has been externally updated. 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 July 20, 2014 by deanishe Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now