SHARE
TWEET

MultiLineOmniFocus w/ Note Splits

n8henrie Apr 11th, 2013 314 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # More information:  http://n8henrie.com/2013/03/send-multiple-tasks-to-omnifocus-at-once-with-drafts-and-pythonista
  2. # Script name: MultiLineOmniFocus
  3. # Drafts "URL Action": pythonista://MultiLineOmniFocus?action=run&argv=[[draft]]
  4. # Modified from email script by OMZ: https://gist.github.com/omz/4073599
  5. # Modified by Jon Kameya on 2013-04-11 to allow '|' to seperate task from note.
  6.  
  7. import smtplib
  8. from email.mime.multipart import MIMEMultipart
  9. from email.MIMEText import MIMEText
  10. from email import encoders
  11. import sys
  12. import webbrowser
  13. import console
  14.  
  15. def main():
  16.  
  17.         tasks = sys.argv[1].splitlines()
  18.  
  19.         ### CHANGE THESE VALUES:
  20.         to = 'YOUR_MAILDROP_ADDRESS@sync.omnigroup.com'
  21.         gmail_user = 'YOUR_ADDRESS@gmail.com'
  22.         gmail_pwd = 'YOUR_GMAIL_PASSWORD'
  23.  
  24.         console.clear()
  25.         print 'Starting SMTP Server'
  26.  
  27.         smtpserver = smtplib.SMTP("smtp.gmail.com", 587)
  28.         smtpserver.ehlo()
  29.         smtpserver.starttls()
  30.         smtpserver.ehlo
  31.         smtpserver.login(gmail_user, gmail_pwd)
  32.  
  33.         for task in tasks:
  34.                 if task=='':
  35.                         print 'No Task' + str(tasks.index(task) + 1) + ': Blank Line'
  36.                         continue
  37.                 outer = MIMEMultipart()
  38.                 outer['To'] = to
  39.                 outer['From'] = gmail_user
  40.                 outer.preamble = 'You will not see this in a MIME-aware email reader.\n'
  41.  
  42.                 if len(task.split("|")) == 1:
  43.                         outer['Subject'] = task
  44.                 else:
  45.                         tprime = task.split("|")
  46.                         outer['Subject'] = str(tprime[0]).strip()
  47.                         outer.attach(MIMEText(str(tprime[1]).strip()))
  48.  
  49.                 composed = outer.as_string()
  50.  
  51.                 print 'Sending Task ' + str(tasks.index(task) + 1)
  52.                 smtpserver.sendmail(gmail_user, to, composed)
  53.  
  54.         smtpserver.close()
  55.         print 'Done'
  56.         console.clear()
  57.  
  58. if __name__ == '__main__':
  59.         main()
  60.  
  61. webbrowser.open('drafts://')
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top