Opening a foreign file from Mathematica
- To: mathgroup at smc.vnet.net
- Subject: [mg78810] Opening a foreign file from Mathematica
- From: "Steve Luttrell" <steve at _removemefirst_luttrell.org.uk>
- Date: Tue, 10 Jul 2007 06:29:43 -0400 (EDT)
Yes, that reads "from" not "in" Mathematica. Several years ago I asked in this forum how to create a hyperlink in a Mathematica notebook that when clicked would open a file in its associated application, thus emulating the effect of double-clicking on the file (at least in MS Windows, that is). Here is (part of) a response to that: ======================================= Working in Windows I guess you should not have any problems in doing this. Just create a normal hyperlink button, but set the ButtonData to: {URL["fullfilename"], None} where, fullfilename is the full path to the file you want to open (with backslashes doubled as is normal in Mathematica strings). An example cell expression which might open a Word document: Cell[BoxData[ ButtonBox["test", ButtonData:>{ URL[ "C:\\temp\\foo.doc"], None}, ButtonStyle->"Hyperlink"]], "Input"] ======================================= This worked perfectly which is why I kept the code snippet for future use, but I somehow lost the name of whoever wrote this response. I have always been frustrated that the full path to the file was needed in this approach, because this locked down the notebook/file pair to a single place in the filesystem, and this approach broke even if you subsequently changed only the name of (i.e. letter assigned to) your hard drive. Many of my past links have been broken in this way. This is not ideal. I have tried the obvious approach to using relative paths: SetDirectory[NotebookDirectory[]] Cell[BoxData[ ButtonBox["test", ButtonData:>{ URL[ ".\\temp\\foo.doc"], None}, ButtonStyle->"Hyperlink"]], "Input"] which I hoped would work from a notebook stored at the top level of C: (in this example), but unfortunately it doesn't work. So, the question is how to generalise this so that you can use paths relative to the notebook. -- Steve Luttrell West Malvern, UK