Send Selected OmniFocus Task to Plain Text File

I save a lot of stuff into OmniFocus: bits of text, URLs, emails. I used to save favorite tweets into it, too. The app’s Quick Entry panel is so easy to invoke and so well-integrated with core parts of OS X  that, most of the time, I find myself clipping information that shouldn’t be into OmniFocus at all. However, I also find the process of manually going through that information beneficial to my workflow: it allows me to mentally and practically separate actionable items (tasks) from things to read and things to write (Instapaper material and my future articles, essentially).

I have created a simple AppleScript to send the selected OmniFocus task to a text file. The script is meant for how I use OmniFocus; hopefully you’ll find it useful as well. Feel free to modify it.

Typically, when I decide to go through my OmniFocus inbox, I find a lot of tasks that are actually ideas of things I want to do or write. Ideas don’t go into OmniFocus. Until those ideas become actionable items, I send them to a text file so I can elaborate on them and see if they can evolve. Like I said, most of the time those ideas are for new articles.

I store all my notes in a single Apps/ directory on my Dropbox. Based off the same AppleScript, I have created a Keyboard Maestro macro to create a new text file for each processed task; this is for ideas I know will turn out to be single, standalone articles. For ideas I’m not so sure about, I prefer to append them as text to an Ideas.txt file I keep in Dropbox as an “everything bucket” for inspiration.

AppleScript

This is the underlying AppleScript:

tell application "OmniFocus"

	tell front window

		set my_sel to selected trees of content

		set my_selection to value of item 1 of my_sel

		set task_name to get name of my_selection

		set a_note to get note of my_selection

	end tell

end tell

Simple enough, it grabs the name and note of a selected task in OmniFocus (I am assuming you’ll run this script when OmniFocus is the frontmost window, as you’re processing your Inbox or another perspective). The implementation varies slightly between Keyboard Maestro (which creates single files) and Ideas.txt.

Keyboard Maestro

The macro, pictured below, uses Keyboard Maestro Engine’s support for variables in AppleScript to assign a task’s name and note (if any) to two separate variables. It then brings up a user prompt to confirm you want to name a text file as the task’s name, and use the task’s note for the file’s contents.

The %Variable%TaskName% defines the path for “Write Text to File” you see at the end of the macro, so make sure the file path works for you.

tell application "OmniFocus"

	tell front window

		set my_trees to selected trees of content

		set my_selection to value of item 1 of my_trees

		set task_name to get name of my_selection

		set task_note to get note of my_selection

		tell application "Keyboard Maestro Engine"

			make variable with properties {name:"TaskNote", value:task_note}

			make variable with properties {name:"TaskName", value:task_name}

		end tell

	end tell

end tell

The macro is designed to understand if TaskNote is empty, and, in that case, it won’t add any text to the newly created TaskName file. You can download the macro here.

Append to File

When I want to append a selected task to an existing Ideas.txt file, I use an AppleScript. You can trigger AppleScripts in a variety of ways these days (Alfred, LaunchBar, Keyboard Maestro), including putting them in the OmniFocus toolbar (to do so, place them in ~/Library/Scripts/Applications/OmniFocus/).

-- PATH OF TEXT FILE YOU'LL APPEND TEXT TO

property text_file : "/Users/viticci/Dropbox/Apps/Ideas.txt"


-- GET TASK NAME AND NOTE FROM OMNIFOCUS

tell application "OmniFocus"

	tell front window

		set my_sel to selected tree of content

		set my_selection to value of item 1 of my_sel

		set task_name to get name of my_selection

		set a_note to get note of my_selection

		-- CHECK IF NOTE IS EMPTY

		if a_note is not "" then

			set task_note to {" - " & a_note}

			
			-- APPEND DATE, TASK NAME + NOTE TO IDEAS.TXT FILE
	
			do shell script "echo \"


_\"`date +'%Y-%m-%d'`\"_\" >> " & text_file

			do shell script "echo " & task_name & task_note & ">> " & text_file

			
		else if a_note is "" then

			
			-- APPEND DATE AND TASK NAME TO IDEAS.TXT FILE
	
			do shell script "echo \"


_\"`date +'%Y-%m-%d'`\"_\" >> " & text_file

			do shell script "echo " & task_name & ">> " & text_file

		
		end if

	end tell

end tell

This variation of the AppleScript gets the task’s name and note, and appends them after a date string to an Ideas.txt file.

You can edit the property text_file at the top of the script to set it to your path; note that, if a task has an empty note, only the name will be appended.

Wrap-Up

Personally, I use this at the end of each day to go through my OmniFocus inbox and create text files for ideas I’ve saved. The script works particularly well with nvALT if you’ve set the app to pick up .txt files off a local folder. If you happen to build a modification of the script for a different workflow, feel free to ping me.

Access Extra Content and Perks

Founded in 2015, Club MacStories has delivered exclusive content every week for nearly a decade.

What started with weekly and monthly email newsletters has blossomed into a family of memberships designed every MacStories fan.

Learn more here and from our Club FAQs.

Club MacStories: Weekly and monthly newsletters via email and the web that are brimming with apps, tips, automation workflows, longform writing, early access to the MacStories Unwind podcast, periodic giveaways, and more;

Club MacStories+: Everything that Club MacStories offers, plus an active Discord community, advanced search and custom RSS features for exploring the Club’s entire back catalog, bonus columns, and dozens of app discounts;

Club Premier: All of the above and AppStories+, an extended version of our flagship podcast that’s delivered early, ad-free, and in high-bitrate audio.