_mk_ Posted April 11, 2013 Posted April 11, 2013 (edited) Bash Workflow Handler As my OmniFocus workflow does most of its work in the shell, I created a bash workflow handler to reduce the overhead when creating feedback xml and dealing with preferences. Download Download it from GitHub and put it into your workflow directory. Usage Import handler into your script . workflowHandler.sh Create feedback XML # create feedback entries addResult "uid" "arg" "title" "subtitle" "icon" "valid" "autocomplete" # get feedback xml getXMLResults Get BundleID BUNDLEID="$(getBundeId)" Get data dir DATADIR=$(getDataDir) Get cache dir CACHEDIR=$(CACHEDIR) Store preferences # store volatile setPref "key" "value" 0 # store non-volatile setPref "key" "value" 1 Read preferences # read volatile pref MYVAR=$(getPref "key" 0) # read non-volatike pref MYVAR=$(getPref "key" 1) Edited May 7, 2013 by _mk_ vdesabou and stouty 2
vdesabou Posted April 11, 2013 Posted April 11, 2013 Cool, I'll definitely use it in the future! Would it be possible to add the 'autocomplete' in addResult() ?
vdesabou Posted April 11, 2013 Posted April 11, 2013 Done... Thanks. I wanted to use your workflow to get the path of the Data directory, (as the data() method in http://dferg.us/workflows-class/ php) I ended up doing: oldIFS="$IFS" IFS=$'\n' NVPREFS="${HOME}/Library/Application Support/Alfred 2/Workflow Data/" BUNDLEID=$(/usr/libexec/PlistBuddy -c "Print :bundleid" "info.plist") cp ${NVPREFS}${BUNDLEID}/myfile.txt ${NVPREFS}${BUNDLEID}/myfile.txt.bak #rm library.json.bak IFS="$oldIFS" It would be nice to have such kind of method in you workflow handler :-)
_mk_ Posted April 12, 2013 Author Posted April 12, 2013 (edited) This would simply be: DATAPATH="${NVPREFS}${getBundleId}" But I could add a convenience method to make things more comfortable. Also be sure to always quote your paths as the path includes spaces. That way you don't have to deal with the IFS. Edited April 12, 2013 by _mk_
_mk_ Posted April 12, 2013 Author Posted April 12, 2013 I updated the handler to include two new convenience functions the get the DATA and CACHE dir of the workflow. I also changed the order of the arguments of the addData function to better handle empty values for valid and autocomplete.
vdesabou Posted April 12, 2013 Posted April 12, 2013 I updated the handler to include two new convenience functions the get the DATA and CACHE dir of the workflow. I also changed the order of the arguments of the addData function to better handle empty values for valid and autocomplete. Thanks!!Very cool
_mk_ Posted April 12, 2013 Author Posted April 12, 2013 Based on the comments by Vítor in another thread I changed the license of the workflow handler to be as permissive as possible. I do not want to throw obstacles in people's ways when using the handler. So feel free to do whatever you want with it.
oderwat Posted April 13, 2013 Posted April 13, 2013 In addition to autocomplete there should be the type(='file') so the results can be drag&drop if they are path's.
_mk_ Posted April 20, 2013 Author Posted April 20, 2013 I made an important update to the workflowHandler: When generating the feedback XML special chars are properly escaped. Trying to save preferences with the & char caused weired behavior on the shell Everyone using the workflowHandler should update to the latest version.
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