The Omni Group
These forums are now read-only. Please visit our new forums to participate in discussion. A new account will be required to post in the new forums. For more info on the switch, see this post. Thank you!

Go Back   The Omni Group Forums > OmniFocus > OmniFocus Extras
FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
Applescript to write todays completed tasks to a text file Thread Tools Search this Thread Display Modes
Hi.

I'm setting out to write a log script, that records my daily activities to a text file. It's mostly for my amusement -- the older I get the more value I see in having a record of what I do from day to day.

I'd like it to work something like this: every night the script (run by launchd) extracts the days events from iCal, as well as the completed items for that day from OmniFocus. The script will append these data to a plain text file -- my log.

I'm a very inexperienced applescripter and I must say I find OmniFocus script support a little hard to grasp. Is there anyone out there who has written a script to retrieve todays completed tasks, or is there someone kind enough to help me out with the OmniFocus-portion of this project?

I would be most grateful.

/Joakim Hertze
 
Joakim,

The most interesting/challenging part of scripting batch queries like yours in OF is finding all the tasks. The OF Applescript dictionary doesn't support batch operations, so you have to write a script that "walks" down all the folders, projects, action groups, and actions in the database, checking each for whether it matches what you're looking for. There are a few scripts out there that already do this. One example is my Verify Next Actions Exist script, available from my software page. You could use that script as a basis but tweak how it decides which items to add to its list and which items to ignore.

An alternative would be to create a script that uses perspectives. Create a context-mode perspective showing completed items grouped by completion date, with all groups collapsed except Completed Today. Your script would then open that perspective and grab the visible actions. My old Send OmniFocus items to OmniOutliner might serve as a useful skeleton for grabbing the visible actions.

Cheers,

Curt
__________________
Cheers,

Curt
 
Skinning the cat in a different way, you might start with a perspective as Curt suggests, then use UI scripting to select all the items, copy them to the clipboard, and paste them at the end of your text file in TextEdit or BBEdit or TextWrangler or the like. This approach would only get the task names, however. A web page with a reasonable example of this technique can be found at http://www.elegantchaos.com/node/159

I would agree that using the Applescript primitives supplied by OmniFocus is a more robust solution, but the UI scripting bit is a useful thing to know when you're needing to script something where the developer hasn't given you the tools.
 
Thank you for your advice!

I opted for the simpler solution, using a "flat" perspective, containing all completed actions in context mode.

I've attached my script to this post. It's ugly, but it seems to work. I've patched it together from fragments of other scripts, using a *lot* of trial and error.

/Joakim
Attached Files
File Type: zip loggbok.zip (7.9 KB, 475 views)
 
Any advice.. I get the following error "OmniFocus got an error: Canít get completion date of value of tree 1 of content of document window"
 
Quote:
Originally Posted by Bemused View Post
Any advice.. I get the following error "OmniFocus got an error: Canít get completion date of value of tree 1 of content of document window"
In OF 1.8 the do_OmniFocus function can be written a little more simply, without creating a window and reading values from trees.

If you are running OF 1.8 you could try replacing it with something like:

Code:
on do_OmniFocus(strText)
	set dteToday to date (short date string of (current date))
	tell application id "com.omnigroup.OmniFocus"
		tell default document
			set refDoneToday to a reference to (flattened tasks where (completion date ≥ dteToday))
			set {lstName, lstContext, lstProject} to {name, name of its context, name of its containing project} of refDoneToday
			set strText to ""
			repeat with iTask from 1 to count of lstName
				set {strName, varContext, varProject} to {item iTask of lstName, item iTask of lstContext, item iTask of lstProject}
				set strText to strText & "OmniFocus: " & tab & strName
				if varContext is not missing value then set strText to strText & " @" & varContext
				if varProject is not missing value then set strText to strText & " (" & varProject & ")"
				set strText to strText & return
			end repeat
		end tell
	end tell
	strText
end do_OmniFocus
--

Last edited by RobTrew; 2010-08-30 at 08:32 AM..
 
Interesting, thanks I'lll take a look
 
Works a treat - thanks
 
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
AppleScript for Generating a Report of Completed Tasks gattaca Applying OmniFocus 1 2013-02-24 06:23 AM
What happens to attached file once they are completed? enigma2k OmniFocus 1 for Mac 4 2012-11-28 01:02 AM
AppleScript for deleting completed tasks and projects snarke OmniFocus Extras 8 2009-01-20 02:22 PM
applescript to export to text file? jbaile38 OmniFocus Extras 3 2008-09-06 12:01 PM
Applescript example: exporting to a text file RobTrew OmniFocus Extras 6 2007-09-11 08:27 PM


All times are GMT -8. The time now is 07:30 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2019, vBulletin Solutions, Inc.