The Omni Group Forums

The Omni Group Forums (http://forums.omnigroup.com/index.php)
-   OmniFocus Extras (http://forums.omnigroup.com/forumdisplay.php?f=44)
-   -   Applescript to write todays completed tasks to a text file (http://forums.omnigroup.com/showthread.php?t=13849)

december76 2009-09-14 12:39 AM

Applescript to write todays completed tasks to a text file
 
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

curt.clifton 2009-09-14 10:06 AM

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 [URL="http://www.rose-hulman.edu/~clifton/software.html"]my software page[/URL]. 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 [URL="http://www.rose-hulman.edu/~clifton/software.html#SendOF-OO"]Send OmniFocus items to OmniOutliner[/URL] might serve as a useful skeleton for grabbing the visible actions.

Cheers,

Curt

whpalmer4 2009-09-14 10:18 AM

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 [URL="http://www.elegantchaos.com/node/159"]http://www.elegantchaos.com/node/159[/URL]

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.

december76 2009-09-14 11:23 AM

1 Attachment(s)
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

Bemused 2010-08-29 09:30 AM

Not quite working for me
 
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"

RobTrew 2010-08-29 01:21 PM

[QUOTE=Bemused;84499]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]

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[/CODE]

[COLOR="White"]--[/COLOR]

Bemused 2010-09-01 11:58 PM

Interesting, thanks I'lll take a look

Bemused 2010-09-02 11:03 AM

Works a treat - thanks


All times are GMT -8. The time now is 09:53 AM.

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