PDA

View Full Version : OmniFocus URI Handler (create tasks via URL) [See Omni note on pg 5!]


iNik
2008-06-20, 10:34 AM
OmniFocus URI Handler (http://inik.net/omnifocus-uri-handler)

This little applet takes an "x-omnifocus:" URL and turns it into an OmniFocus inbox task. You use standard web syntax like this to create your new tasks:

x-omnifocus:newtask?name=foo&context=bar&notes=barfoo

It also lets you pass things like the context and project via the URL. Furthermore, you can decide whether to route the task to Quick Entry or straight into the inbox (&quickentry=1).

Lastly, it also permits a "parsetasks" handler so that you can parse multiple tasks by passing them in a URL.

Bookmarklets are provided in the read-me file that's included with the applet itself. One nice feature of the bookmarklets is that they save any selected text in your browser as a note, along with the URL.

My goal here was not just to have browser-bookmarklet support (although that's what started it off), but also to have an easy way to "glue" other programs into OmniFocus, especially programs that aren't scriptable. I just took my lead from all the simple "REST" apis on the web these days and essentially created my own little REST service for OmniFocus.

I use this now with a handful of shell scripts as well as bookmarklets.

iNik
2008-06-20, 10:42 AM
Just posted a new version. If you picked it up in the first few minutes it was out, please re-download.

http://inik.net/omnifocus-uri-handler

Toadling
2008-06-20, 10:49 AM
Very nice! Thanks for posting!

-Dennis

wfiveash
2008-06-28, 09:46 AM
First, thanks for the app and bookmarks. I use Firefox and this is def. needed. Second, for those that aren't as browser/app savvy it would be good to provide more info on how to install/configure this stuff. What I did was drag the OmniFocus URI handler app to my Applications folder and then manually created a bookmark in Firefox by using the copy link location function via the cntrl-mouse click in either Safari or FF. Then in FF I went to the bookmark manager and manually created a bookmark whose location was the pasted contents of the copied link.

iNik
2008-06-29, 02:33 PM
Easier still: Take the links on the download page and drag 'em to your browser's toolbar.

v.bampton
2008-09-07, 01:27 AM
Perfect! Thank you!!!

sawxray
2008-10-08, 07:56 AM
The method is unclear, despite the efforts of iNik and wfiveash...:(

I also cannot find a download link to drag to my toolbar...double :(

Could someone spell it out just a bit for me?

Thanks!

whpalmer4
2008-10-08, 08:46 AM
Here's a screen capture from iNik's web page.

http://img338.imageshack.us/img338/3791/picture17zn2.png (http://imageshack.us)

See where it says "Send Page to OmniFocus"? That is one of the links in question, and the rest follow it. Drag whichever one(s) strike your fancy to your bookmark bar after installing his software (click on the "OmniFocus URI Handler" link below Version History) and you should be in business.

iNik
2008-10-12, 12:24 PM
Thanks for the feedback. I added a little help on how to install the bookmarklets on the page.

kingsinger
2008-11-10, 09:44 PM
Boy, I wish there was a way that this could work with Thunderbird to put info into omni.

sawxray
2008-11-16, 08:37 AM
Thank you all for the guidance. The script is great, and the bookmarklets work great in Safari and in Firefox.

Cheers!

iNik
2008-11-24, 08:16 AM
Thank you all for the guidance. The script is great, and the bookmarklets work great in Safari and in Firefox.

FYI: The OmniFocus service to create a task on ^T works great in Safari and may well be preferable.

sawxray
2008-12-06, 05:23 AM
Surprise!

This fine script just up and quit on me...

It worked fine, but suddenly I can get it to open OF, but not to make an entry in either the Inbox or the Quick Entry window.

Notes:

Still works fine in Safari.

Properties of bookmarklets are unchanged, when compared with those in Safari.

I tried re-installing the script in my Apps folder.

I tried re-installing the bookmarklets in my Bookmarks bar.

The Services->OmniFocus choices are grayed out in FireFox, but normal in Safari.

I am using FF 3.0.4 (just upgraded). Could that be the problem?

Thanks!

iNik
2008-12-11, 12:45 PM
I am using FF 3.0.4 (just upgraded). Could that be the problem?

Could be. I haven't tested it. I don't have the script or Firefox handy. Has anyone else tried it?

sawxray
2008-12-12, 10:10 PM
A few more details:

If I do not select any text, 'Send to Inbox' does not work. That is, my keyboard shortcut does nothing, and the 'Services->OmniFocus:Send to Inbox' entry is greyed out.

If I select text, my keyboard shortcut works by opening up a Quick Entry window in Safari, Mail, TextEdit. But in FF, even with text selected, the keyboard shortcut elicits an error sound, and no entry is made in the OF Inbox. Or...if I have the OF prefs set to send clippings to a QuickEntry window, no window opens up.

Again, it works fine in other apps, but makes only an error sound in FF.

Thanks.

iNik
2008-12-17, 11:35 AM
I've tested this in FireFox 3.04 without trouble.

I dragged both links on the download page (which is broken, thanks to an ill-considered domain transition) into my toolbar and both worked straight out of the gates.

I then added a keyword to each (sof and sofq for send to OF and send to Quick Entry, respectively) and typing in those keywords into the address bar properly ran the script and sent the page to OF.

I suspect you have a conflicting add-on in Firefox. NoScript, Greasemonkey and adblock/adblock plus are typical suspects.

Try disabling your add-ons and see if it starts working.

iNik
2008-12-17, 11:39 AM
If I do not select any text, 'Send to Inbox' does not work. That is, my keyboard shortcut does nothing, and the 'Services->OmniFocus:Send to Inbox' entry is greyed out.

If I select text, my keyboard shortcut works by opening up a Quick Entry window in Safari, Mail, TextEdit. But in FF, even with text selected, the keyboard shortcut elicits an error sound, and no entry is made in the OF Inbox. Or...if I have the OF prefs set to send clippings to a QuickEntry window, no window opens up.[/QUOTE]

You're confusing it with the ^T send to omnifocus service, that's provided by OmniFocus itself, and will only work in applications that support services. Firefox is not one of these -- hence the need for this URI handler.

All this script does is lets you create bookmarklets or otherwise send actions to OmniFocus using a URL scheme. The applet you download is just a handler for these URLs and nothing more. It will NOT work in any application that cannot have a bookmarklet.

sawxray
2008-12-27, 06:26 AM
Thanks for the follow-up.

I disabled add-ons, but no help. I did notice one item, however. Perhaps this will help point the way:

When I use the bookmarklets in Safari, which work fine, I see the OmniFocus URI Handler title show up in the top left title bar as the process completes.

When I use the same bookmarklet in FF, I get an instant change to FireFox in the same location. No evidence the URI Handler is invoked.

If I go to my Applications folder and double-click on the URI Handler script I have placed there, I get a new entry in the OF inbox:

JavaScript escape() Function

with the attachment:

The escape() function encodes a string, so it can be read on all computers.

So I believe the problem may lie in a break between FF and the script in my applications folder.

Any ideas?

Thanks!

Pat
2009-01-03, 07:27 PM
This is exactly what I neeeded. Thanks for the scripts and the explanations.

iNik
2009-01-04, 07:20 AM
When I use the bookmarklets in Safari, which work fine, I see the OmniFocus URI Handler title show up in the top left title bar as the process completes.

When I use the same bookmarklet in FF, I get an instant change to FireFox in the same location. No evidence the URI Handler is invoked.

Again, I've tested this myself in both Firefox 2 and 3 and have no problems, so I can't really speak to what's going on there.

As for the escape function text showing up when you run the program, that's actually some debugging code that I neglected to disable. I was testing URL escaping, and encoded "The javascript escape() function..." as the string to pass to the script.

And, yes, the bookmarklet does escape() the clipped text, but that's a requirement of anything that handles a URI, to ensure that ambiguous spaces and other special characters are passed along reliably.

You may want to check whether Firefox has assigned the OF URI Handler as the appropriate application for x-omnifocus URLs. Go to the Applications tabs of your Firefox Preferences and search for "x-omnifocus." Make sure it exists and that it's set to the right app, and isn't set to "ask" or some other program.

Dogsbreath
2009-01-12, 12:40 PM
This is absolutely excellent.

Thanks a lot iNik

sawxray
2009-01-25, 02:34 PM
You may want to check whether Firefox has assigned the OF URI Handler as the appropriate application for x-omnifocus URLs. Go to the Applications tabs of your Firefox Preferences and search for "x-omnifocus." Make sure it exists and that it's set to the right app, and isn't set to "ask" or some other program.

THAT did it!

I went to Preferences->Applications and found x-omnifocus. The 'Action' was set to Firefox. When I changed it to the URI Handler, both 'Send Page to OF' and 'OF Quick Entry' (my bookmarklets) worked as expected. Hopefully, this little hiccough will help a few people in the future.

NOW I am happy!

Just one more little Q: After using one of these bookmarklets, the new entry is created in OF, but the active app remains Firefox. So, I use one of these, and then have to switch to OF. Is there any way to have OF become the new active app upon using this action?

Thanks again for following up, Nik.

Regards,
Scott

Jay Levitt
2009-07-19, 03:11 AM
N.B. for latecomers like me: The Omnifocus URL scheme has apparently changed from "x-omnifocus:" to simply "omnifocus:". You'll need to edit that in the bookmarklet to get it working - but it works great otherwise w/OF 1.6.1!

morren
2009-08-12, 11:11 AM
Both the QuickEntry and the regular OF bookmarklet (with the "x-" change) bring OF to the fore, but don't create a task. Any ideas?

curt.clifton
2009-08-12, 07:37 PM
I wonder if the Quick Entry window is opening off-screen somehow.

If you open Quick Entry from the menu in OF (Window → Show Quick Entry), does it appear? If not, does that menu item at least change to "Hide Quick Entry"?

Dogsbreath
2009-08-13, 10:33 AM
No, the QE window is not opening off screen.

Window/Show QE shows the QE window

Dogsbreath
2009-08-13, 10:34 AM
Both the QuickEntry and the regular OF bookmarklet (with the "x-" change) bring OF to the fore, but don't create a task. Any ideas?

Are you using Firefox? I am and I think that the last update broke these shortcuts.

morren
2009-08-17, 02:20 PM
Yep. I'm on FF 3.5.2.

Would be cool to fix this. Plus I imagine it could be used with the new "send to" function in Google Reader?

kaijin
2009-08-27, 11:59 PM
Both the QuickEntry and the regular OF bookmarklet (with the "x-" change) bring OF to the fore, but don't create a task. Any ideas?

I'm experiencing a similar issue after updating to OF 1.7. Since I did not observe this behavior using the previous stable version of OF and Firefox 3.5.2, I did not make the “x-” change to the bookmarklet. I have now made the “x-” change.

Triggering the QuickEntry bookmarklet brings the OF application to the fore, but does not open the QuickEntry window. The File menu displays “Show Quick Entry”, so it is not opening off-screen. When I trigger the QE window using the menu item or shortcut, however, the web page has been added as a task. Clicking “Save” then adds the task to OF.

The “Send page to OF” bookmarklet produces the error message “Malformed URL:”, followed by the bookmarklet code. The web page is not added to OF as a task.

OSX 10.5.8
OF 1.7
Firefox 3.5.2

kaijin
2009-08-29, 07:39 AM
Despite the change in OF's url scheme (mentioned above (http://forums.omnigroup.com/showthread.php?t=8251&page=3)), I've reverted the url in the bookmarklets from “omnifocus” back to “x-omnifocus”. The Send Page to OF bookmarklet functions properly now—the page is sent to OF and FF remains in the fore.

The Send Page to OF QuickEntry continues to function as I described—the Quick Entry window is not opened and OF is brought to the fore. Opening the QuickEntry window shows the page and clicking Save adds it as an action to OF. As I recall, prior to FF 3.5.2 and/or OF 1.7.1, using the OF QE bookmarklet opened the QE window, displaying the web page as an action ready to be saved to OF.

curt.clifton
2009-08-29, 08:08 AM
You might want to file a bug report to Omni (Help → Send Feedback) about the QE not opening. They changed some of the internals on opening the QE window with 1.7, so this could be a regression.

Brian
2009-09-02, 02:47 PM
I'm checking with Ken to be sure, but I think what happened here is that Mail on the iPhone OS made a change which broke our "send settings in an email" feature. I think fixing that on the phone required a change which caused the bookmarklet to stop working on the Mac.

Of course, I could be remembering this incorrectly. More info soon.

Brian
2009-09-03, 01:38 PM
Turns out I was incorrect about what happened here - I forgot that the bookmarklet sends information along to an applet instead of OmniFocus itself.

We made a change in 1.7 that probably affects the applet that the bookmarklet sends data to:

Updated our AppleScript terminology to use "open quick entry" rather than "activate quick entry". Hopefully this will eliminate the problems people have occasionally encountered in trying to activate the app itself. (Compiled scripts which used our old activate verb may need to be recompiled, however!)

So, once folks recompile the applet to use "open quick entry" instead of "activate quick entry", the bookmarklet should start working again.

kaijin
2009-09-03, 05:54 PM
Thanks for the information, Brian! I changed “activate” to “open” within the QE entry in the URI script and the bookmarklet functions correctly now. Here is the the modified script if anyone else is interested.

(*
# OMNIFOCUS URI HANDLER

This applet enables you to create new tasks using an "x-omnifocus" URL. This is particularly designed to make it easy to add tasks from a web browser via a bookmarklet, without having to code a separate script for each browser. This also works in browsers that don't support AppleScript. (I'm looking at you, Firefox!!!)

It also supports more advanced URLs containing context and project assignments that you're likely to create from web page bookmarklets. This functionality can be utilized to make it easier to add OmniFocus tasks from other applications, shell scripts, etc., without having to hook into complicated AppleScript.

## HOW TO CREATE PROPER URLS

All URLs must use the "x-omnifocus:" URI. You can have "whack whacks" after the URI, or just a colon, your choice. You must then follow the URI with the following methods:

*x-omnifocus:newtask*

This creates a new task. You can pass variables, following the example below. The only required element is "name".

x-omnifocus://newtask?name=**task name**&project=**project name**&context=**context name**&note=**task note text**&quickentry=**1/0**

**Project Name** and **Context Name** will "fuzzy match" an existing project or context, so you don't need a full or exact name.

a **Quickentry** value of "1" will cause the task to go into the Quick Entry window, which will be activated, rather than straight into the inbox.

*x-omnifocus:parsetasks*

This parses tasks either as a single task or as multiple tasks, per the usual parsing syntax. You can pass two variables, the text to parse and whether to parse it as a single task, as below. The only required element is the text to parse.

x-omnifocus://parsetasks?text=**Text to Parse**&single=**1/0**

A *single* value of "1" will make the tasks parse as single tasks. Otherwise, tasks will be parsed line-by-line, potentially as multiple tasks.

All strings should be URL encoded to eliminate any ambiguity in URLs and whatnot.

*** BOOKMARKLETS TO GET YOU STARTED ***

Here's some sample bookmarklets you can put into your browser's toolbar to make this all go:

*Add the current page as a task with the page's URL and any selected text as the note:*

javascript:window.location='x-omnifocus://newtask?name='+encodeURIComponent(document.title)+ '&note='+encodeURIComponent(window.location+'\n\n')+ encodeURIComponent(getSelection())+'&quickentry=0';

*Same as above, but route to the Quick Entry window instead of directly into the inbox:*

javascript:window.location='x-omnifocus://newtask?name='+encodeURIComponent(document.title)+ '&note='+encodeURIComponent(window.location+'\n\n')+ encodeURIComponent(getSelection())+'&quickentry=1';

*Parse tasks in the selection:*

javascript:window.location='x-omnifocus://parsetasks?text='+encodeURIComponent(getSelection( ))+'&single=0';

## NOTES

The HTML entity decoding routine falls down on certain characters, particularly Unicode characters.

If you use the quick entry window with the "newtask" method, the project and context values will be ignored, as these are not scriptable in the quick entry window.

## VERSION HISTORY

• 1.0 - 06/20/2008: Initial release. Supports parsetasks, newtask
• 1.x - 09/03/2009: Modified iNik's script to support new AppleScript terminology used after OF 1.7 update. "activate" changed to "open" for QuickEntry. This version corrects an issue with the QuickEntry window failing to open when the bookmarklet is used in Firefox 3.5.2. Refer to http://forums.omnigroup.com/showthread.php?t=8251 for details. - kaijin

*)

property theURI : "x-omnifocus"
global tid -- save text item delimiters

-- Test it here
on run
open location "x-omnifocus://newtask?name=JavaScript%20escape%28%29%20Function&note=The%20escape%28%29%20function%20encodes%20a%2 0string%2C%20so%20it%20can%20be%20read%20on%20all% 20computers.&quickentry=0&context=P"

--open location "x-omnifocus:parsetasks?text=foo
--bar
--rawr&single=0"

-- open location "ofinbox://?title=JavaScript%20escape%28%29%20Function&selection=kittykat"

end run

(* Open the URI: link *)
on open location sURL

try
if sURL does not start with (theURI & ":") then error "Malformed URL: " & sURL number 400
set tid to AppleScript's text item delimiters

set theSplitURL to splitURL(sURL)

set theMethod to (decode_text(item 1 of theSplitURL))

if item 2 of theSplitURL is not missing value then
set theArgs to my parseArgs(item 2 of theSplitURL)
end if

if theMethod is "newtask" then
my newTask(theArgs)
else if theMethod is "parsetasks" then
my parseTasks(theArgs)
else
error "Method \"" & theMethod & "\" not allowed." number 405
end if

on error errMsg number errNum
display alert errMsg & " (" & errNum & ")"
error number -128
end try
end open location

on newTask(theArgs)
-- x-omnifocus://newtask?name=[task name, required]&project=[project name]&context=[context name]&note=[task note text]&quickentry=[1: Use quickentry]

log "newTask"
log theArgs
set useQuickEntry to false -- default to no quick entry
set hasName to false -- Check to see if it has a name, otherwise it'll break
set theParameters to {}
set theNote to missing value
set theContext to missing value
set theProject to missing value
set theName to missing value

repeat with x in theArgs
set xKey to key of x
set xVal to value of x


-- Name
if xKey is "name" then
set theName to xVal

-- Note
else if xKey is "note" then
set theNote to xVal

-- QuickEntry
else if xKey is "quickentry" and xVal is "1" then
set useQuickEntry to true

-- Project
-- Match the project to the closest match in the document, error if something doesn't match
else if xKey is "project" then
try
tell application "OmniFocus" to tell default document to get name of first item of (complete xVal as project maximum matches 1)
set theProject to (result as text)
on error errMsg number errNum
if errNum is -1728 then
error "Project \"" & xVal & "\" not found." number 404
else
error errMsg number errNum
end if
end try

-- Context
-- Match the context to the closest match in the document, error if something doesn't match
else if xKey is "context" then
try
tell application "OmniFocus" to tell default document to get name of first item of (complete xVal as context maximum matches 1)
set theContext to (result as text)
on error errMsg number errNum
if errNum is -1728 then
error "Context \"" & xVal & "\" not found." number 404
else
error errMsg number errNum
end if
end try
end if

end repeat -- We have all the arguments now

log "Arguments repeat finished"

if theName is missing value then -- no name, no new task
error "No name specified. New tasks must have a name." number 406
else if useQuickEntry is true then
my makeQuickEntryTask(theName, theNote) -- Context and Project are not scriptable in QE mode
else
my makeInboxTask(theName, theProject, theContext, theNote)
end if

end newTask

on parseTasks(theArgs)
-- x-omnifocus://parsetasks?text=[Text to Parse, HTTP escaped, required]&single=[1: Parse as a single task]
set theText to missing value
set single to false

repeat with x in theArgs
set xKey to key of x
set xVal to value of x
if xKey is "text" then
set theText to xVal
else if xKey is "single" and xVal is "1" then
set single to true
end if
end repeat

if theText is missing value then -- error, we need transport text
error "No text specified. New tasks must include text to parse." number 406
else if single is true then
tell application "OmniFocus" to tell default document to parse tasks with transport text theText with as single task
else
tell application "OmniFocus" to tell default document to parse tasks with transport text theText without as single task
end if

end parseTasks

on makeQuickEntryTask(theName, theNote)
tell application "OmniFocus" to tell default document
tell quick entry
set theTask to make new inbox task with properties {name:theName}
if theNote is not missing value then set note of theTask to theNote
select {theTask}
open
end tell
end tell
end makeQuickEntryTask

on makeInboxTask(theName, theProject, theContext, theNote)
tell application "OmniFocus" to tell default document
set theTask to make new inbox task with properties {name:theName}
if theNote is not missing value then set note of theTask to theNote
end tell
end makeInboxTask

(* Convert a URL into a record set *)
on splitURL(theURL)


set uriN to (count of characters of theURI) + 1 -- account for the ":"
-- Get rid of the url protocol string

set pN to offset of (theURI & "://") in theURL -- is it a mailto:// style?

if pN > 0 then -- a URI:// url
set theURL to text (uriN + 3) through (count of characters of theURL) of theURL
else -- or just a URI: url
set theURL to text (uriN + 1) through (count of characters of theURL) of theURL
end if

-- See if there's any arguments being passed, pass 'em back if there are
set aN to offset of "?" in theURL
if aN = 1 then -- no base url, just arguments
return {missing value, (text (aN + 1) through (count of characters of theURL) of theURL)}
else if aN > 1 then
return {(text 1 through (aN - 1) of theURL), (text (aN + 1) through (count of characters of theURL) of theURL)}
else
return {theURL, missing value}
end if

end splitURL

on parseArgs(sArgs)
set text item delimiters to "&"
set theArgs to every text item of sArgs
set text item delimiters to tid
set rArgs to {}

repeat with xArg in theArgs
set yArg to (text of xArg)
set eqOff to offset of "=" in yArg
if eqOff > 0 then
set argKey to text 1 through (eqOff - 1) of yArg
set argValueEncoded to text (eqOff + 1) through (count of characters of yArg) of yArg
set argValue to my decode_text(argValueEncoded)
set rArgs to rArgs & {{key:argKey, value:argValue}}
else
error "Parameter \"" & yArg & "\" has no value." number 406
end if
end repeat

return rArgs
end parseArgs

(* From Apple's sub-routines page *)
-- this sub-routine is used to decode a three-character hex string
on decode_chars(these_chars)
copy these_chars to {indentifying_char, multiplier_char, remainder_char}
set the hex_list to "123456789ABCDEF"
if the multiplier_char is in "ABCDEF" then
set the multiplier_amt to the offset of the multiplier_char in the hex_list
else
set the multiplier_amt to the multiplier_char as integer
end if
if the remainder_char is in "ABCDEF" then
set the remainder_amt to the offset of the remainder_char in the hex_list
else
set the remainder_amt to the remainder_char as integer
end if
set the ASCII_num to (multiplier_amt * 16) + remainder_amt
return (ASCII character ASCII_num)
end decode_chars

-- this sub-routine is used to decode text strings
on decode_text(this_text)
set flag_A to false
set flag_B to false
set temp_char to ""
set the character_list to {}
repeat with this_char in this_text
set this_char to the contents of this_char
if this_char is "%" then
set flag_A to true
else if flag_A is true then
set the temp_char to this_char
set flag_A to false
set flag_B to true
else if flag_B is true then
set the end of the character_list to my decode_chars(("%" & temp_char & this_char) as string)
set the temp_char to ""
set flag_A to false
set flag_B to false
else
set the end of the character_list to this_char
end if
end repeat
return the character_list as string
end decode_text

morren
2009-09-07, 07:59 AM
Still doesn't work for me. I didn't study it line by line, but looks like the above post might still be the original code?

kaijin
2009-09-07, 09:55 AM
The only change I made was in this entry:
on makeQuickEntryTask(theName, theNote)
tell application "OmniFocus" to tell default document
tell quick entry
set theTask to make new inbox task with properties {name:theName}
if theNote is not missing value then set note of theTask to theNote
select {theTask}
open
end tell
end tell
end makeQuickEntryTask
where I changed “activate” to “open”. This corrected the issue where the QuickEntry window failed to open after recent updates to OF and Firefox.

I also reverted the “x-change”, changing “omnifocus:” back to “x-omnifocus:” in the bookmarklet. Making the “x-change” in the bookmarklet; then the bookmarklet and the script—both the orginal and modified versions—did not correct the issue for me.

Interesting to note, while experimenting with the bookmarklet and script, I tested versions and combinations which failed to work. When I then replaced an experimental script with the modified one—the one I posted reflecting only the “open” change, which I knew to work—the QuickEntry bookmarklet failed to function properly until quitting and restarting Firefox. Until quitting and restarting FF, using the bookmarklet—despite pointing to the working modified script—would only produce whatever error message or faulty behavior the replaced experimental script had produced.

The steps that revived a broken QE bookmarklet for me:

Revert the QuickEntry bookmarklet location to:
javascript:window.location='x-omnifocus://newtask?name='+encodeURIComponent(document.title)+ '&note='+encodeURIComponent(window.location+'\n\n')+ encodeURIComponent(getSelection())+'&quickentry=1';
Replace the OF URI Handler script with the modified version I posted upthread.
Confirm that FF Preferences > Applications > x-omnifocus is set to Use OmniFocus URI Handler (default).
Quit and restart FF.
Test the QuickEntry bookmarklet. (You may be prompted to confirm and open the new application).

eatmytag
2009-09-09, 04:06 AM
Thanks for the information, Brian! I changed “activate” to “open” within the QE entry in the URI script and the bookmarklet functions correctly now. Here is the the modified script if anyone else is interested.

Very cool! Thanks for the fix!

Rock
2009-10-25, 09:55 AM
I was not able to copy selected text from a Gmail message into the Omnifocus task note field until I replaced the function call

getSelection()

with the following code

document.getElementById('canvas_frame').contentWin dow.getSelection()

The resulting note isn't pretty. Some end-of-line characters get translated into other characters, but it's good enough for my purposes.

Here's the entire script:
javascript:window.location='x-omnifocus://newtask?name='+encodeURIComponent(document.title)+ '&note='+encodeURIComponent(window.location+'%5Cn%5C n')+encodeURIComponent(document.getElementById('ca nvas_frame').contentWindow.getSelection())+'&quickentry=0';

I am unable to get the quick entry script provided by kaijin to work. If I have the Quick Entry window open it will populate it with the new task, but it will not open the window and bring it to the foreground. No success with either FF or Safari.

kingsinger
2009-11-14, 03:54 PM
The changes suggested here got it working for me in FF, but not in Safari or Fluid.app. Too bad, this was a cool thing and working quite well in 1.6.

If anyone has any suggestions Safari/Fluid, please let me know.

jmca
2010-02-24, 06:21 AM
Nice job on the script!! 1 prob, for some reason it will not recognize the &project parameter. Everything works except that it ignores this parameter and chucks it in the inbox, both with quickentry 1 or 0.

jmca
2010-02-24, 07:00 AM
Just a quick update. I changed the makeInboxTask function, a bit of a sloppily re-write, but it now works with a project:


on makeInboxTask(theName, theProject, theContext, theNote)
tell application "OmniFocus" to tell default document
set theTask to make new inbox task with properties {name:theName}
if theNote is not missing value then set note of theTask to theNote
if theContext is not missing value then set context of theTask to theContext

if theProject is not missing value then
set theProject to project theProject
set assigned container of theTask to theProject
compact
end if
end tell
end makeInboxTask

jmca
2010-02-24, 07:07 AM
Re-write again for context:



on makeInboxTask(theName, theProject, theContext, theNote)
tell application "OmniFocus" to tell default document
set theTask to make new inbox task with properties {name:theName}
if theNote is not missing value then set note of theTask to theNote

if theContext is not missing value then
set theContext to context theContext
set context of theTask to theContext
end if

if theProject is not missing value then
set theProject to project theProject
set assigned container of theTask to theProject
compact
end if
end tell
end makeInboxTask

kaijin
2010-02-26, 05:31 AM
Issues with Send to Quick Entry script:

In Firefox 3.6, if OF is hidden:
-Script calls QE and new task is created, but QE does not have focus. You must click on a field to edit or save, which calls the OF main window behind QE.

In Firefox 3.6, if OF is minimized or not the frontmost window:
-Script calls QE and new task is created, but QE does not have focus. You must click on a field to edit or save, which calls the OF Inspectors palette.

I believe this began after updating to Firefox 3.6. Similar behavior occurs in Safari 4.0.4, however. The only difference is that QE receives focus and the cursor is active in the Name field of the new task (but the OF main window or the Inspectors window is still called).

This has been observed in 1.7.5 and 1.8sp (v77.46 r126553)

(Incidentally, the Send to OF Quick Entry bookmarklet that was posted in the 1.8 sneaky peak thread does not function for me in Firefox 3.6, either. In Safari 4.0.4, it produces the same behavior as above. Feedback has been sent to the support ninjas).

Nice job on the script!! 1 prob, for some reason it will not recognize the &project parameter. Everything works except that it ignores this parameter and chucks it in the inbox, both with quickentry 1 or 0.
Additionally, I'm not having the issue mentioned by jmca. New tasks created via QE are correctly placed in their assigned project and context.

iNik
2010-05-26, 01:01 PM
NOTE: I've stopped developing this script because as of OF 1.8 (currently in SneakyPeekdom), this functionality is built-in through omnifocus://add URLs.

However, here is a snazzy bookmarklet that does the same thing with OF 1.8, including saving the selection. Just drag the link below to your toolbar:

Send to OF (javascript:window.location='omnifocus:///add?note='+encodeURIComponent(window.location+'\n\ n')+encodeURIComponent(getSelection())+'&name='+encodeURIComponent(document.title))

Or the raw JS:

javascript:window.location='omnifocus:///add?note='+encodeURIComponent(window.location+'\n\ n')+encodeURIComponent(getSelection())+'&name='+encodeURIComponent(document.title)

Brian
2010-10-20, 03:49 PM
We were contacted today by a developer wondering if this was the best way to satisfy their customers' request for adding "Send to OmniFocus" features to their app.

There's a different method which we would actually recommend; folks can read about it in this thread (http://forums.omnigroup.com/showthread.php?t=14986).

Just wanted to head off any potential future confusion at the pass. (Editing the thread title to that end, as well.)