-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathOF→iDoneThis.applescript
110 lines (88 loc) · 3.53 KB
/
OF→iDoneThis.applescript
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
(*
Email Selected Tasks to iDoneThis
# DESCRIPTION #
This script generates an email from selected OmniFocus tasks to send to iDoneThis. Each task title is presented on a separate line.
# LICENSE #
Copyright 2014-2015 Dan Byler (contact: [email protected])
Licensed under MIT License (http://www.opensource.org/licenses/mit-license.php)
(TL;DR: no warranty, do whatever you want with it.)
# CHANGE HISTORY #
1.0 (2015-07-19) Original release
# INSTALLATION #
- Copy this script to OmniFocus scripts folder
- To find this, in OmniFocus, go to Help -> Open Scripts Folder
- If desired, add to the OmniFocus toolbar using View > Customize Toolbar...
*)-- To change settings, modify the following propertiesproperty defaultRecipient : ""property fromAddress : ""property mailClient : "" --options: Mail, Postbox, or Otherproperty includeProject : true --if true, includes the task's Project title in bracketson main() set email_list to {} tell application "OmniFocus" tell content of front document window of front document --Get selection set validSelectedItemsList to value of (selected trees where class of its value is not item and class of its value is not folder) set totalItems to count of validSelectedItemsList if totalItems is 0 then my notifyWithoutGrowl("No valid task(s) selected") return end if set theSubject to my pyFormatTime(current date, "%A, %B %e") set theRecipient to defaultRecipient set theBody to "" repeat with thisItem in validSelectedItemsList set theTitle to name of thisItem if includeProject then try set theParentName to (name of containing project of thisItem) set theTitle to theTitle & " [" & theParentName & "]" end try end if set theBody to theBody & theTitle & "
" end repeat my sendMessage(theRecipient, theSubject, theBody) end tell end tellend mainon sendMessage(emailRecipient, emailSubject, emailBody) if mailClient = "Mail" then tell application "Mail" activate set theOutMessage to make new outgoing message with properties {visible:true} tell theOutMessage make new to recipient at end of to recipients with properties {address:emailRecipient} set sender to fromAddress set subject to emailSubject set content to emailBody end tell end tell else if mailClient = "Postbox" then tell application "Postbox" activate send message subject emailSubject body emailBody recipient emailRecipient end tell else set emailSubject to (my replace_chars("&", "–", emailSubject)) set emailBody to (my replace_chars("&", "–", emailBody)) tell application "System Events" to open location "mailto:" & emailRecipient & "?subject=" & emailSubject & "&body=" & emailBody end ifend sendMessageon pyFormatTime(AS_Date, AS_Format) set timeFormat to quoted form of AS_Format return (do shell script "/usr/bin/python -c \"import time, dateutil.parser; print dateutil.parser.parse('" & AS_Date & "').strftime(" & timeFormat & "); \"")end pyFormatTimeon replace_chars(search_string, replacement_string, this_text) set AppleScript's text item delimiters to the search_string set the item_list to every text item of this_text set AppleScript's text item delimiters to the replacement_string set this_text to the item_list as string set AppleScript's text item delimiters to "" return this_textend replace_charson notifyWithoutGrowl(alertText) tell application "OmniFocus" to display dialog alertText with icon 1 buttons {"OK"} default button "OK"end notifyWithoutGrowlmain()