Jump to content
Sign in to follow this  
_mk_

Bash workflow handler

Recommended Posts

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 by _mk_

Share this post


Link to post

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 :-)

Share this post


Link to post

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 by _mk_

Share this post


Link to post

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.

Share this post


Link to post

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

Share this post


Link to post

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.

Share this post


Link to post

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.

Share this post


Link to post

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
Sign in to follow this  
×