Skip to content

Instantly share code, notes, and snippets.

@richie5um
Created September 21, 2012 21:53
Show Gist options
  • Save richie5um/3764163 to your computer and use it in GitHub Desktop.
Save richie5um/3764163 to your computer and use it in GitHub Desktop.
Completed OmniFocus Tasks --> Brett Terpstra's Slogger --> DayOne Journal
=begin
Plugin: OmniFocus
Description: Grabs completed tasks from OmniFocus
Author: [RichSomerfield](www.richsomerfield.com)
=end
config = {
'omnifocus_description' => [
'Grabs completed tasks from OmniFocus'],
'omnifocus_tags' => '@tasks',
'omnifocus_save_hashtags' => true
}
$slog.register_plugin({ 'class' => 'OmniFocusLogger', 'config' => config })
class OmniFocusLogger < Slogger
def do_log
if @config.key?(self.class.name)
# We don't have any config, so don't need to worry about it not being there ;-)
else
@log.warn("<Service> has not been configured or a feed is invalid, please edit your slogger_config file.")
return
end
@log.info("Logging <Service> for completed tasks")
additional_config_option = config['additional_config_option'] || false
tags = config['tags'] || ''
tags = "\n\n#{@tags}\n" unless @tags == ''
today = @timespan
output = ''
# Run an embedded applescript to get today's completed tasks
values = %x{osascript <<'APPLESCRIPT'
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 & 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
return strText
APPLESCRIPT}
values.each do |value|
# Create entries here
output += "* " + value + "\n"
end
# Create a journal entry
unless output == ''
options = {}
options['content'] = "## OmniFocus - Completed Tasks\n\n#{output}#{tags}"
sl = DayOne.new
sl.to_dayone(options)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment