Advertisement
n8henrie

MultiLine OmniFocus via Pythonista and Drafts

Feb 23rd, 2013
1,724
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.32 KB | None | 0 0
  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.  
  5. # Modified from email script by OMZ: https://gist.github.com/omz/4073599
  6.  
  7. import smtplib
  8. from email.mime.multipart import MIMEMultipart
  9. from email import encoders
  10. import sys
  11. import webbrowser
  12. import console
  13.  
  14. def main():
  15.  
  16.     tasks = sys.argv[1].splitlines()
  17.  
  18.     ### CHANGE THESE VALUES:
  19.     to = 'Your_OmniFocus_Mail_Drop_Email_Address'
  20.     gmail_user = 'Your_Gmail_Address'
  21.     gmail_pwd = 'Your_Gmail_Pass (or OTP if using 2FA)'
  22.  
  23.     console.clear()
  24.     print 'Starting SMTP Server'
  25.    
  26.     smtpserver = smtplib.SMTP("smtp.gmail.com", 587)
  27.     smtpserver.ehlo()
  28.     smtpserver.starttls()
  29.     smtpserver.ehlo
  30.     smtpserver.login(gmail_user, gmail_pwd)
  31.  
  32.     for task in tasks:     
  33.         outer = MIMEMultipart()
  34.         outer['Subject'] = task
  35.         outer['To'] = to
  36.         outer['From'] = gmail_user
  37.         outer.preamble = 'You will not see this in a MIME-aware email reader.\n'
  38.  
  39.         composed = outer.as_string()
  40.        
  41.         print 'Sending Task ' + str(tasks.index(task) + 1)
  42.         smtpserver.sendmail(gmail_user, to, composed)
  43.  
  44.     smtpserver.close()
  45.     print 'Done'
  46.     console.clear()
  47.    
  48. if __name__ == '__main__':
  49.     main()
  50.  
  51. webbrowser.open('drafts://')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement