Amazon.com Widgets
Twitter » Linkedin » Flickr » DjangoPeople » Feed
...not so private reflections of greg.newman
RSS feed - Categories & Search

Applescript to Send Safari Url to Emacs Org-Mode

I've been a long time OmniFocus user and am a daily (or habitual) emacs user so it only makes sense for me to dabble with org mode for a GTD system. After all, when I'm writing code, why not have my projects todo lists in the next window. So this morning I figured I'd give org mode a try. It's not polished like OmniFocus or Things but seriously; why does a todo list need satin pajamas? I'm not sure I'll stick with it but I at least need to give it a trial run for a week or two.

How I Roll
When I get an email from a client that needs attention I use the clipper that comes with OmniFocus (Clip-o-tron 3000) to create a new task with a link to the email embedded. I also like to send research urls from Safari for projects to my todo lists as notes. This helps keep me on top of things (if that's possible) as projects progress.

The Immediate Problem; No Clip-O-Tron
Since org-mode is basically a text file displayed within emacs, I need a way to send these to my org-mode file. I'm using gmail these days (trying to) and gmail has unique addresses for each email. All I need is to capture that url and send to org-mode.

Applescript to the rescue!
I wrote this applescript today that will capture the url from the foremost Safari window and save it to my org-mode file where I keep a "Inbox" at the very bottom of my file. Before saving the link I have it prompt me for a title for the link so that I can name it something meaningful. After it saves it to the end of my file, I get a growl notification telling me it's done.

The AppleScript

To use this effectively, change the line 19 which reads set theFilePath to "Macintosh HD:Users:greg:gtd:" & "greg.org" as string to the path where your org file is located. I also keep my "Inbox" at the bottom of my org file so that when these new urls are saved, they are appended to the bottom of the inbox.

If you can't get the script from this page, you can grab it over at Snipt here: http://snipt.net/gregnewman/send-safari-url-to-emacs-org-mode

If you use this script and find it useful, leave a comment and let me know about it. If you have ways to make it better, I'd love to see your changes.

11 Comments

Why ever leave emacs? gnus for mail and w3m for browsing. :)

More complex, but more flexible, is to use AppleScript to call emacsclient and use some elisp to format the link via org-make-link. The link can then be copied to the kill-ring or processed with remember templates to insert the link and associated data into an org page.

I achieve this using a Safari, Quicksilver and Emacs combo.

But...

Whilst copying the link to the kill-ring works fine, the remember part is currently broken, and I've been putting off fixing it whilst a major rewrite of org-remember is underway. If I've got time to fiddle a temporary fix I'll post back...

Sorry, dud HTML in the previous post.

The link you may be looking for is:

http://claviclaws.net/org/index.html

Seth...
I personally don't use w3m simply because my work requires me to constantly be using Safari and/or FF. As far as mail goes, never tried using mail in emacs.

Christopher...
Your solution looks very nice at first glance. I haven't used quicksilver in a while. I've been using launchbar for the past few months and wonder what (if anything) would need changed for it to work with it.

Thanks for posting that and please do report back if you fix remember

Christopher...
I fired up quicksilver and gave your files a try. Doesn't seem to work at least with my emacs 23. It does open the remember buffer and capture the text but C-c C-c fails with "org-remember-finalize: This does not seem to be a remember buffer for Org-mode". Not sure if this is what you're referring to about the remember bug.

I fear so.

Sorry to link to my own broken hacks, but I just wanted to point out the possibilities. I hope to try and fix things this week...

No need for apologies. I've enjoyed poking around your scripts. Since I'm just scratching the surface with org mode, it's helpful Christopher.

This script is awesome! I can easily link my Trac tickets to org-mode.


Thanks,
Cezar

Glad you like it Cezar. I'm doing some more modifications to it this week to try and get emacsclient to process it so I don't have to revert-buffer every time I add it. I also noticed when calling the script from quicksilver the prompt for title gets hidden sometimes so that will be fixed as well.

Greg,

New version up at http://claviclaws.net/org/

Now works with the latest org-mode from git and emacs23. Can be customised much more easily for the various flavours of OS X Emacs. And a good excuse to tidy up the code.

As far as adapting to work with Launch Bar goes, the only QuickSilver specific code is in the AppleScripts:

using terms from application "Quicksilver"
...
end using terms from

Assuming there is a similar method of getting text from LaunchBar via AppleScript, the conversion should be trivial.

Christopher

Very cool Christopher. I'll give it another try today. I think I saw the announcement on the org-mode list. Thanks.

Leave a comment