Creating an OmniFocus task with the Safari page

| 2 Comments

Yesterday, I described how to send the current tweet in Twitterrific to OmniFocus. Today, I'll show you how to create an OmniFocus task containing the URL and title of the current window in Safari.

At first, I thought that I wouldn't need to write this script, since OmniFocus can bring in the current Safari URL using the Clippings feature. However, in order for this to work, some text in the web page must be selected first (which will become the title of the task). I'm fine with always using the title of the page, so I don't need to worry about finding the title somewhere on the page to copy it.

Anyway, the URL and title of the active Safari window need to be retrieved with AppleScript. For some reason, the document object contains the URL, while the window contains the title. They can be found like this:

tell application "Safari"
    set u to URL of front document
    set t to name of front window
end tell
The front modifier tells Safari which property to route the request to. This ensures that the window that you're working in will be the one that gets the request. Now that we have the URL and title, the same code that was used yesterday to create the task can be reused here, plugging in the data from above:
tell application "OmniFocus"
    tell default document
        set theProject to "Follow Up"
        set theContext to context "Online"
            of context "Mac" of context "Home"
        make new inbox task with properties
            {name:t, note:u, context:theContext}
        set assigned container of newTask to project theProject
        compact
    end tell
end tell
And that's it! As always, if you have any questions, comments, or suggestions, please let me know.

2 Comments

thanks for these. There's a minor typo that will break the script where you have got 'documnet' in the second script though!

I fixed the typo. Thanks for pointing it out. :)