emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* org-capture and org-link-type for Outlook mail messages on Mac OSX
@ 2012-06-03 10:56 Christopher J. White
  2012-06-03 11:16 ` Christopher J. White
  2012-06-05 23:00 ` Mike McLean
  0 siblings, 2 replies; 3+ messages in thread
From: Christopher J. White @ 2012-06-03 10:56 UTC (permalink / raw)
  To: emacs-orgmode

Hi Folks,

I thought I'd share a bit of hacking I've been doing over the last 
couple days.

I had 2 basic needs:
   * create a TODO entry associated with an email message
   * include a clickable link back to that message in the entry

For work email I use Outlook on a Mac.  After some digging, I managed to 
cobble together an AppleScript with some glue lisp that solves both of 
the above.

Testing is minimal at this point, but it works for me so, I thought I'd 
share it here first, then if folks think appropriate, I can post it up 
on the worg.

I have hopes to extend support to Thunderbird (which I use for personal 
email), but there appears to be very limited AppleScript support, so 
does not look promising.

...cj

-- OutlookToEmacsOrg
--
-- This script uses org-protocol to capture the currently selected 
message in outlook
-- as an Org item.  The item creates a link of type 'mac-outlook' with 
the message ID
-- within Outlook that can later be used by mdfind to find that message.
--
-- If more than one message is selected, only the first message is 
used.  If no message
-- is selected, the script does nothing.
--
-- The Title passed to org-protocol is formatted as "[Sender] Subject", 
but could
-- easily be modifed as below to any text.
--
-- See http://orgmode.org/worg/org-contrib/org-protocol.html for details 
about
-- how org-protocol works.
--
-- This script assumes emacsclient is available via the Carbon Emacs 
application, but
-- can be changed via the emacsclientBinary below.
--
-- Script Installation for Outlook
--   1. Startup AppleScript Editor
--   2. Paste this script into a new file
--   3. Save as "OutlookToEmacsOrg" of file type "Script Bundle" in the 
directory:
--        /Users/<you>/Library/Application 
Support/Microsoft/Office/Outlook Script Menu Items
--  4. Restart Outlook, and this should show up in the Script menu (the 
squiggly next to Help)
--
-- You probably also assign a shortcut via System Preferences.
--
-- Emacs mac-outlook link support, put the following in your .emacs:
--
-- (org-add-link-type "mac-outlook" 'org-mac-outlook-open)
--
-- (defun org-mac-outlook-open (msgid)
--   "Open a message in outlook"
--   (shell-command (format "open \"`mdfind 
com_microsoft_outlook_recordID==%s`\"" msgid)))
-- 
-- Tested on Mac OS X 10.7.3, Emacs 23.4.2, Org 7.8.03, Outlook for Mac 2011
-- 
-- Special thanks to Lutz Meyer / LuMe96(at)gmail.com -- I got the critical
-- pieces of applescript from OutlookToThings.scpt written by Lutz.

property emacsclientBinary : 
"/Applications/Emacs.app/Contents/MacOS/bin/emacsclient"

on urlencode(plaintext)
     set enctext to do shell script "python -c 'import sys, urllib; 
print urllib.quote(sys.argv[1])' " & quoted form of plaintext
     return enctext
end urlencode

tell application "Microsoft Outlook"
     set msgCount to count current messages
     if (msgCount < 1) then
         return
     end if

     set myMessage to (the first item of (get current messages))
     set myID to id of myMessage as string
     set mySubject to subject of myMessage
     set mySender to sender of myMessage
     set mySenderName to name of mySender

     set myTitle to "[" & mySenderName & "] " & mySubject

     set myCmd to emacsclientBinary & " \"org-protocol:/capture:/eo"
     set myCmd to myCmd & "/mac-outlook:" & myID
     set myCmd to myCmd & "/" & (my urlencode(myTitle))
     set myCmd to myCmd & "\""

     --display dialog myCmd
     tell application "Emacs"
         activate
     end tell
     do shell script myCmd
     set the clipboard to myCmd
end tell

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: org-capture and org-link-type for Outlook mail messages on Mac OSX
  2012-06-03 10:56 org-capture and org-link-type for Outlook mail messages on Mac OSX Christopher J. White
@ 2012-06-03 11:16 ` Christopher J. White
  2012-06-05 23:00 ` Mike McLean
  1 sibling, 0 replies; 3+ messages in thread
From: Christopher J. White @ 2012-06-03 11:16 UTC (permalink / raw)
  To: emacs-orgmode

Ok -- just realized I had left in the selection of a custom 
org-capture-template which will likely not be in anyone else's config, 
so I made the org-capture-template configurable, and set to nil by default.

Modified script below..

...cj

-- OutlookToEmacsOrg
--
-- This script uses org-protocol to capture the currently selected 
message in outlook
-- as an Org item.  The item creates a link of type 'mac-outlook' with 
the message ID
-- within Outlook that can later be used by mdfind to find that message.
--
-- If more than one message is selected, only the first message is used. 
  If no message
-- is selected, the script does nothing.
--
-- The Title passed to org-protocol is formatted as "[Sender] Subject", 
but could
-- easily be modifed as below to any text.
--
-- See http://orgmode.org/worg/org-contrib/org-protocol.html for details 
about
-- how org-protocol works.
--
-- This script assumes emacsclient is available via the Carbon Emacs 
application, but
-- can be changed via the emacsclientBinary below.
--
-- Script Installation for Outlook
--   1. Startup AppleScript Editor
--   2. Paste this script into a new file
--   3. Save as "OutlookToEmacsOrg" of file type "Script Bundle" in the 
directory:
--        /Users/<you>/Library/Application 
Support/Microsoft/Office/Outlook Script Menu Items
--  4. Restart Outlook, and this should show up in the Script menu (the 
squiggly next to Help)
--
-- You probably also assign a shortcut via System Preferences.
--
-- Emacs mac-outlook link support, put the following in your .emacs:
--
-- (org-add-link-type "mac-outlook" 'org-mac-outlook-open)
--
-- (defun org-mac-outlook-open (msgid)
--   "Open a message in outlook"
--   (shell-command (format "open \"`mdfind 
com_microsoft_outlook_recordID==%s`\"" msgid)))
-- 
-- Tested on Mac OS X 10.7.3, Emacs 23.4.2, Org 7.8.03, Outlook for Mac 2011
-- 
-- Special thanks to Lutz Meyer / LuMe96(at)gmail.com -- I got the critical
-- pieces of applescript from OutlookToThings.scpt written by Lutz.

property emacsclientBinary : 
"/Applications/Emacs.app/Contents/MacOS/bin/emacsclient"

-- Set to the empty string to use the default capture template, or fill
-- in the letter code from org-capture-templates
property orgCaptureTemplate : ""
--property orgCaptureTemplate : "x"

on urlencode(plaintext)
	set enctext to do shell script "python -c 'import sys, urllib; print 
urllib.quote(sys.argv[1])' " & quoted form of plaintext
	return enctext
end urlencode

tell application "Microsoft Outlook"
	set msgCount to count current messages
	if (msgCount < 1) then
		return
	end if
	
	set myMessage to (the first item of (get current messages))
	set myID to id of myMessage as string
	set mySubject to subject of myMessage
	set mySender to sender of myMessage
	set mySenderName to name of mySender
	
	set myTitle to "[" & mySenderName & "] " & mySubject
	
	set myCmd to emacsclientBinary & " \"org-protocol:/capture:"
	if (length of orgCaptureTemplate > 0) then
		set myCmd to myCmd & "/" & orgCaptureTemplate
	end if
	
	set myCmd to myCmd & "/mac-outlook:" & myID
	set myCmd to myCmd & "/" & (my urlencode(myTitle))
	set myCmd to myCmd & "\""
	
	--display dialog myCmd
	tell application "Emacs"
		activate
	end tell
	do shell script myCmd
	set the clipboard to myCmd
end tell

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: org-capture and org-link-type for Outlook mail messages on Mac OSX
  2012-06-03 10:56 org-capture and org-link-type for Outlook mail messages on Mac OSX Christopher J. White
  2012-06-03 11:16 ` Christopher J. White
@ 2012-06-05 23:00 ` Mike McLean
  1 sibling, 0 replies; 3+ messages in thread
From: Mike McLean @ 2012-06-05 23:00 UTC (permalink / raw)
  To: orgmode; +Cc: emacs-orgmode


On Jun 3, 2012, at 6:56 AM, Christopher J. White wrote:

> Hi Folks,
> 
> I thought I'd share a bit of hacking I've been doing over the last couple days.
> 
> I had 2 basic needs:
>  * create a TODO entry associated with an email message
>  * include a clickable link back to that message in the entry
> 
> For work email I use Outlook on a Mac.  After some digging, I managed to cobble together an AppleScript with some glue lisp that solves both of the above.

Well, wow. I've had “write an Outlook / Org integration” on my TODO list for too long. I too use Outlook for Mac at work and will certainly be testing this over the next few days. Thank you!

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2012-06-05 23:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-06-03 10:56 org-capture and org-link-type for Outlook mail messages on Mac OSX Christopher J. White
2012-06-03 11:16 ` Christopher J. White
2012-06-05 23:00 ` Mike McLean

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).