Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I have a bunch of cells containing text and hyperlinks. i.e. of the form:

Cell[TextData[{
 "Text",
 ButtonBox["Linktext",
  BaseStyle->"Hyperlink",
  ButtonData->"linktag"],
 "more text"
}], "Text"] 

Is there a automated way of changing all of the link destinations so that they link to the same tag as the original, but in a different file, like this:

Cell[TextData[{
 "Text",
 ButtonBox["Linktext",
  BaseStyle->"Hyperlink",
  ButtonData->{"filename", "linktag"}],
 "more text"
}], "Text"] 

Note that "linktag" is a different string for most of the cells.

share|improve this question
add comment

2 Answers 2

up vote 4 down vote accepted

Modifying Rolf's answer slightly you have.

Button["change",
 NotebookPut[
  (NotebookGet[EvaluationNotebook[]]) /. 
   ButtonBox["Linktext", BaseStyle -> "Hyperlink", ButtonData -> x_] ->
     ButtonBox["Linktext", BaseStyle -> "Hyperlink", 
     ButtonData -> {"filename", x}]
  ]
 ]
share|improve this answer
    
I can't make your button work. When I select a cell and click the button (which I put on a palette) nothing happens. Does it work on your machine? And further: I tried changing "Linktext" to y_ and y to make it handle different link texts. Is that the right way to do it? –  Sofic Aug 15 '13 at 19:07
    
@Sofic Try it again. It should open a new Notebook containing new versions. –  Liam William Aug 15 '13 at 19:22
    
Changing EvaluationNotebook to InputNotebook did the trick. Thank you for your help. –  Sofic Aug 15 '13 at 19:22
    
@Sofic Yeah there was a mistake. –  Liam William Aug 15 '13 at 19:23
add comment

Create a button, e.g., like this:

  Button["change",
  NotebookWrite[EvaluationNotebook[], (NotebookRead@EvaluationNotebook[])/."linktag" :>
 {"filename","linktag"}]]

Then select the cells you want to change and click the button: done.

share|improve this answer
    
Thank you, Rolf. It was something like that, I was looking for. It does however not solve my problem completely. I am sorry for not getting all details in my question: The problem is that the "linktag"s are different for most of the cells. –  Sofic Aug 15 '13 at 17:58
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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