Skip to main content
added 153 characters in body
Source Link
Szabolcs
  • 236.5k
  • 31
  • 641
  • 1.3k

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.

I do not have a fix for HyperlinkFirst, but I do have one forlet'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"mailto:*]*"],True,
                      StringMatchQ[s,file"file:*]*"],True,
                      StringMatchQ[s,paclet"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\""]

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.

I do not have a fix for Hyperlink, but I do have one for 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.


Another workaround that is not cross-platform is this:

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

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

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\""]

Source Link
Szabolcs
  • 236.5k
  • 31
  • 641
  • 1.3k

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.

I do not have a fix for Hyperlink, but I do have one for 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.


Another workaround that is not cross-platform is this:

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

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