5
$\begingroup$

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.

3) Click in the hyperlink.


Update

Following this answer, running

Hyperlink["test", MathLink`CallFrontEnd[ FrontEnd`SystemOpen[
 "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", MathLink`CallFrontEnd[ FrontEnd`SystemOpen[
 "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"], MathLink`CallFrontEnd[ FrontEnd`SystemOpen[
  "onenote:///\\\\myComputer\\The%20Notebook&page-id={7D74D7D4E640-4217-9575-877E08975BED}&end"]]
  , Appearance -> None]
$\endgroup$
3
  • $\begingroup$ 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. $\endgroup$
    – Szabolcs
    Commented Sep 26, 2013 at 21:36
  • $\begingroup$ You can also try SystemOpen["URI"], but if Hyperlink didn't work, SystemOpen isn't likely to work either. $\endgroup$
    – Szabolcs
    Commented Sep 26, 2013 at 21:37
  • $\begingroup$ Actually, looking at the source of SystemOpen, here's something that does work on Mac: MathLink`CallFrontEnd[FrontEnd`SystemOpen["URI"]]. It turns out that System`SystemOpen[target] auto-prepends "file://" to target, which destroys the custom URI. So please try this as well, and see if it works on Windows. $\endgroup$
    – Szabolcs
    Commented Sep 26, 2013 at 21:40

1 Answer 1

5
$\begingroup$

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] := MathLink`CallFrontEnd[FrontEnd`SystemOpen[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\""]

$\endgroup$
7
  • $\begingroup$ OneNote URI's have an extra /: "onenote:///". $\endgroup$
    – Hector
    Commented Sep 26, 2013 at 21:55
  • $\begingroup$ "Looking at the source" … you work at Wolfram? $\endgroup$
    – Hector
    Commented Sep 26, 2013 at 21:56
  • $\begingroup$ @Hector They're still of the form *://* $\endgroup$
    – Szabolcs
    Commented Sep 26, 2013 at 21:57
  • $\begingroup$ @Hector No, I just used Information. $\endgroup$
    – Szabolcs
    Commented Sep 26, 2013 at 21:57
  • 1
    $\begingroup$ @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. $\endgroup$
    – Szabolcs
    Commented Sep 26, 2013 at 23:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.