# Handling of non-file URI

According to the manual, Hyperlink “represents a hyperlink that jumps to the specified URI when clicked”. OneNote produces hyperlinks that begin with onenote://. In Mathematica, creating a hyperlink to a OneNote page does not work. It returns a message: “The file that you tried to open was not found…”

According to the manual again, “non-file URI open in a web browser”. When I paste the onenote URI in my web browser, it opens the target.

1) Can you confirm this bug in Mathematica?

2) Does anyone know of a workaround?

Steps:

1) In OneNote right click on a page label and select Copy Link to Page. The clipboard contains something like:

onenote:///XXXX#Compound%20expressions,%20Get%20and%20Goto&page-id={7D74D7D4- E640-4217-9575-877E08975BED}&end

2) Create a text cell, put some text, select and press Ctrl+Shift+H. Paste the OneNote hyperlink.

Update

Hyperlink["test", MathLinkCallFrontEnd[ FrontEndSystemOpen[
"onenote:///\\\\myComputer\\The%20Notebook&page-id={7D74D7D4E640-4217-9575-877E08975BED}&end"]]]


creates a hyperlink that jumps correctly when it is created. If one clicks on the hyperlink, then nothing happens. On the other hand, running

Button["test", MathLinkCallFrontEnd[ FrontEndSystemOpen[
"onenote:///\\\\myComputer\\The%20Notebook&page-id={7D74D7D4E640-4217-9575-877E08975BED}&end"]]]


creates a button with that works correctly.

I will report this as a bug to Wolfram (in the no so near future).

My workaround

For the sake of …, I'll post this workaround. It produces a hyperlink-looking button.

Button[Style["test","Hyperlink"], MathLinkCallFrontEnd[ FrontEndSystemOpen[
"onenote:///\\\\myComputer\\The%20Notebook&page-id={7D74D7D4E640-4217-9575-877E08975BED}&end"]]
, Appearance -> None]

• I see the problem with skype: URIs on Mac. I assume you're using Windows, and the workaround (Run["open URI"]) I used on Mac won't work the same way there. Try this: Run["start \"\" \"URI\""] where you substitute the correct URI, and let me know if it worked. Sep 26, 2013 at 21:36
• You can also try SystemOpen["URI"], but if Hyperlink didn't work, SystemOpen isn't likely to work either. Sep 26, 2013 at 21:37
• Actually, looking at the source of SystemOpen, here's something that does work on Mac: MathLinkCallFrontEnd[FrontEndSystemOpen["URI"]]. It turns out that SystemSystemOpen[target] auto-prepends "file://" to target, which destroys the custom URI. So please try this as well, and see if it works on Windows. Sep 26, 2013 at 21:40

I can reproduce the problem both on OS X and one Windows, but only with URIs of the form foo:something. URIs of the form foo://something do work correctly, both with Hyperlink and with SystemOpen. Your URI is of the :// form, so I am not sure why it doesn't work.

First, let's find out why some URIs don't work with SystemOpen. Looking at the source of SystemOpen, it performs the following test to see if the string that was passed to it is a proper URI:

uriQ[s_String]:=Which[StringMatchQ[s,"mailto:*"],True,
StringMatchQ[s,"file:*"],True,
StringMatchQ[s,"paclet:*"],True,
StringMatchQ[s,"*://*"],True,True,False]


If the uriQ test returns False, it will auto-prepend file:// to the URI, which explains the error message you see.

The workaround is to pass the URI to the Front End for opening directly, without doing the uriQ test first:

openURI[uri_String] := MathLinkCallFrontEnd[FrontEndSystemOpen[uri]]


This works for any URI for me, both on Windows and Mac.

A replacement for Hyperlink is this:

URIlink[name_, uri_] :=
Button[name, openURI[uri], BaseStyle -> "Hyperlink", Appearance -> "Frameless"]


Another workaround that is not cross-platform is this:

• On OS X, Run["open URI"]

• On Windows, Run["start \"\" \"URI\""]

• OneNote URI's have an extra /: "onenote:///". Sep 26, 2013 at 21:55
• "Looking at the source" … you work at Wolfram? Sep 26, 2013 at 21:56
• @Hector They're still of the form *://* Sep 26, 2013 at 21:57
• @Hector No, I just used Information. Sep 26, 2013 at 21:57
• @Hector I usually use this package to look at definitions. It is much more convenient than manually removing ReadProtected and trying to make sense of the unformatted mess printed by Information`. Sep 26, 2013 at 23:13