Omnifocus link for Outlook 365 web email

I have found 2 javascript bookmarklets that allow me to:

  1. Get a link to an Outlook 365 email message in their web app [a link that will re-open the email even when it is moved out of the Inbox]
  2. Send the link to Omnifocus and create a task

Is there a way to combine these two scripts to run as one bookmarklet / click / keyboard shortcut?

Bookmarklets pasted below:
Get Outlook Link:
javascript:(function()%20{%20window.open('https://outlook.office365.com/owa/?ItemID='%20.concat(window.location.href.split("/id/")[1])%20.concat('&exvsurl=1&viewmodel=ReadMessageItem')%20)%20;})()

Send to Omnifocus:
javascript:(function(){var%20enc=encodeURIComponent,w=window,frames=w.frames,d=document,tn=w.getSelection?w.getSelection():(d.getSelection)?d.getSelection():(d.selection?d.selection.createRange().text:0),pu=w.location.href,isGMail=w.location.host.match(/mail\.google\.com/),tt=pt=d.title,subjSpans=d.getElementsByClassName("hP"),i,url;if(isGMail){if(subjSpans){tt=subjSpans[0].innerText}else{tt=d.title.substring(d.title.indexOf("-")+1,d.title.lastIndexOf("-")).replace(/^%20+/,"").replace(/%20+$/,"")};if(tn!="")tn+="\n\n";tn+="From%20email%20subject:("+tt+")\n"+pu;pu="https://mail.google.com/mail/u/0/?qs=true&search=query&q=subject:("+enc(tt)+")"};url='omnifocus:///add?note='+enc(tn+"\n"+pu)+'&name='+enc(tt);w.location.href=url})();

1 Like

I don’t think the Outlook bookmarklet you posted does what you think it does based on what it looks to be telling the browser to execute (just an open widow with some text teling you to sign in). You might want to double check it.

It might also be useful to post the bookmarklets between triple back ticks to mark them as being in code blocks. That stops the forum from changing things like quotes to smart quotes.

Thank you for the “back tick advice” - fixed it and now the real code is visible, not the “sign in to Outlook” text that was being substituted in the post originally!

Totally untested, but maybe something like this?

javascript:(function(){var%20enc=encodeURIComponent,w=window,frames=w.frames,d=document,tn=w.getSelection?w.getSelection():(d.getSelection)?d.getSelection():(d.selection?d.selection.createRange().text:0),pu=w.location.href,isGMail=w.location.host.match(/mail\.google\.com/),tt=pt=d.title,subjSpans=d.getElementsByClassName("hP"),i,url;if(isGMail){if(subjSpans){tt=subjSpans[0].innerText}else{tt=d.title.substring(d.title.indexOf("-")+1,d.title.lastIndexOf("-")).replace(/^%20+/,"").replace(/%20+$/,"")};if(tn!="")tn+="\n\n";tn+="From%20email%20subject:("+tt+")\n"+pu;pu="https://mail.google.com/mail/u/0/?qs=true&search=query&q=subject:("+enc(tt)+")"};url='omnifocus:///add?note='+enc(tn+"\n"+pu+"\n"+window.open('https://outlook.office365.com/owa/?ItemID='%20.concat(window.location.href.split("/id/")[1])%20.concat('&exvsurl=1&viewmodel=ReadMessageItem')))+'&name='+enc(tt);w.location.href=url})();