AIM: I want to create a button that, when clicked, opens another
notebook in the same directory as the one containing that button.
QUESTION 1: Is a hypertext button transportable across platforms and
immune to a move of both the notebooks -- the source with the button
and the target to be opened -- together to another directory? I ask
because I created such a hypertext button and its expression is:
Cell[BoxData[
ButtonBox["Cat",
ButtonData:>{
FrontEnd`FileName[ {
ParentDirectory[ ], "Temp"}, "Cat.nb", CharacterEncoding ->
"WindowsANSI"], None},
ButtonStyle->"Hyperlink"]], "Input"]
This seems to have some hard-coding of the source notebook's current
directory ("Temp") as well as the "WindowsANSI" character encoding.
If this will be OK when I move the notebooks together on my computer, or
transport them to another platform (Mac), then I will be happy.
I will be even happier if I can have an answer to the following
question.
QUESTION 2: Trying to finesse my uncertainty as to the answer to
Question 1, I first tried the following. In one cell I evaluated the
following expression:
thisnotebookdir = "FileName" /.
NotebookInformation[EvaluationNotebook[]]/. FrontEnd`FileName[d_List,
nam_, ___] :> ToFileName[d];
Then I created a button whose expression is:
Cell[BoxData[
ButtonBox[
StyleBox[
RowBox[{"Open", " ", "notebook"}],
FontSize->13,
FontColor->RGBColor[0, 0, 1]],
ButtonFunction:>(NotebookOpen[
StringJoin[ thisnotebookdir, "Cat.nb"]]&),
ButtonEvaluator->Automatic,
Active->True,
ButtonStyle->None,
ButtonNote->"\"Open notebook Cat\""]], "Input",
FontSize->24]
This works just fine. But it is not a clean solution, since it requires
the separately defined variable thisnotebookdir.
So I tried to modify the preceding button expression so as to include
the value that variable in place:
Cell[BoxData[
ButtonBox[
StyleBox[
RowBox[{"Open", " ", "notebook"}],
FontFamily->"Helvetica",
FontSize->13,
FontColor->RGBColor[0, 0, 1]],
ButtonFunction:>(NotebookOpen[
StringJoin[
ReplaceAll[ "FileName",
ReplaceAll[
NotebookInformation[
EvaluationNotebook[ ]], FrontEnd`FileName[ d_List,
nam_, ___] :>
ToFileName[ d]]],
"Cat.nb"]]&),
ButtonEvaluator->Automatic,
Active->True,
ButtonStyle->None,
ButtonNote->"\"Open notebook Cat\""]], "Input",
FontSize->24]
But if I now click on this button, evaluation never seems to end -- the
kernel keeps running an evaluation and the target notebook does not get
opened.
Diagnosis? Cure?
--
Murray Eisenberg Internet:
murray at math.umass.edu
Mathematics & Statistics Dept. Voice: 413-545-2859 (W)
University of Massachusetts 413-549-1020 (H)
Amherst, MA 01003 Fax: 413-545-1801