Hi again,
I found the following script at The Brooks Review ([https://brooksreview.net/2015/07/daily-emails/]), but I can’t seem to get it to work - it sends an email, but the email is empty. This is literally the first time I have opened AppleScript, could anyone with more knowledge have a peek at this to see if there is something simple or obvious to fix? It would be great to be able to send emails with the task list of due today or starting soon (in essence the forecast view).
Many thanks
–==============================
– Script name: Email OmniFocus Task Completion Report
– Version 1.2
– Written By: Phil Gorrindo pgorrindo.github@gorrindo.com and http://phil.gorrindo.com
– Description: This script retrieves a list of OmniFocus tasks completed yesterday or today. It then sends an email report.
– Version History:
– 1.0 - Initial release
– 1.1 - fixed errors on unescaped angle brackets and quotes, and removed context/project title code to speed up script
– 1.2 - added switch for sending email via mail.app or command-line, since command-line doesn’t work with some ISPs
– Based on the following original scripts:
– http://www.tuaw.com/2013/04/15/applescripting-omnifocus-send-completed-task-report-to-evernot/
– http://veritrope.com/code/write-todays-completed-tasks-in-omnifocus-to-a-text-file/
– Great Many Hacks added by: Ben Brooks (brooksreview.net) to make this an email sent to email address.
–==============================
property toAddress : “YOUR EMAIL ADDRESS”
property fromAddress : “YOUR EMAIL ADDRESS”
–property theReportScope : “Yesterday”
property theReportScope : “Today”
– send the email via Mail.app or via command-line. Command-line won’t always work, if an ISP blocks this
– possible options: “mail.app” | “cli”
property emailMethod : “mail.app”
set theMessage to my do_OmniFocus()
my send_email(theMessage)
on do_OmniFocus()
set theStartDate to current date
set hours of theStartDate to 0
set minutes of theStartDate to 0
set seconds of theStartDate to 0
set theEndDate to theStartDate + (23 * hours) + (59 * minutes) + 59
if theReportScope = "Today" then
--then do nothing
else if theReportScope = "Yesterday" then
set theStartDate to theStartDate - 1 * days
set theEndDate to theEndDate - 1 * days
end if
set theMessage to "<html><head>
<style>
h2 {font-size: 24px;font-family: -apple-system, HelveticaNeue, LucidaGrande;color:#1FB0E0 ;margin-top: 30px;margin-bottom: 0;}
h3, h4 {font-size: 22px;font-family: -apple-system, HelveticaNeue, LucidaGrande;font-weight: normal;margin-bottom: 10px;}
ul {font-family: -apple-system, HelveticaNeue, LucidaGrande;margin: 0;}
li {font-size: 18px;list-style-type: circle;}
hr {border: 2px solid #eee; }
body {width: 90%;margin:auto;font-family: -apple-system, HelveticaNeue, LucidaGrande;}
</style>
Upcoming tasks for " & (date string of theStartDate) & "
"
tell application "OmniFocus"
activate
tell default document
--getting the due tasks
set refDoneTasks to a reference to (flattened tasks where (due date ≥ theStartDate) and (due date ≤ theEndDate))
set numberTasks to count of refDoneTasks
set theMessage to theMessage & "<h4>Number of tasks due: " & numberTasks & "</h4><br>"
set theMessage to theMessage & "<ul>"
set {lstName} to {name} of refDoneTasks
repeat with iTask from 1 to count of lstName
set {strName} to {item iTask of lstName}
set strName to my remove_quotes(strName)
set theMessage to theMessage & "<li>" & strName
set theMessage to theMessage & "</li><br>"
end repeat
set theMessage to theMessage & "</ul><hr>"
--now we go get the starting tasks
set refDeferTasks to a reference to (flattened tasks where (defer date ≥ theStartDate) and (defer date ≤ theEndDate))
set numberDeferTasks to count of refDeferTasks
set theMessage to theMessage & "<h4>Number of tasks starting: " & numberDeferTasks & "</h4><br>"
set theMessage to theMessage & "<ul>"
set {lstName} to {name} of refDeferTasks
repeat with iTask from 1 to count of lstName
set {strName} to {item iTask of lstName}
set strName to my remove_quotes(strName)
set theMessage to theMessage & "<li>" & strName
set theMessage to theMessage & "</li><br>"
end repeat
set theMessage to theMessage & "</ul>"
end tell
end tell
set theMessage to theMessage & "</body></html>"
end do_OmniFocus
on send_email(theMessage)
set theTimeStamp to (do shell script “date ‘+%Y-%m-%d’”)
set theSubject to “Your Daily Agenda For (” & theTimeStamp & “)”
if emailMethod is equal to "mail.app" then
tell application "Mail"
activate
set theNewMessage to make new outgoing message with properties {subject:theSubject, visible:false} -- visible MUST be false to work
tell theNewMessage
set html content to theMessage -- must set the HTML CONTENT rather than the CONTENT
make new to recipient at end of to recipients with properties {address:toAddress}
send
--set theNewMessage to make new outgoing message with properties {subject:theSubject, html content:theMessage}
--set sender of theNewMessage to fromAddress
--tell theNewMessage
--make new to recipient at end of to recipients with properties {address:toAddress}
--send
end tell
end tell
else if emailMethod is equal to "cli" then
do shell script "echo " & quote & theMessage & quote & " | mail -s \"$(echo \"" & theSubject & "
Content-Type: text/html")" " & toAddress & " -f " & fromAddress
end if
end send_email
on remove_quotes(strName)
set astid to AppleScript’s text item delimiters
set AppleScript’s text item delimiters to quote
set strName to text items of strName
set AppleScript’s text item delimiters to “”
set strName to strName as text
set AppleScript’s text item delimiters to astid
return strName
end remove_quotes