Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Let's say I have a function of the form.


What would be the most automated way and flexible way to generate an input cell of the form,

enter image description here

such that when you press the File Button and select "C:\\Users\\path\\testing.txt" it autofill with the textual arguments.

enter image description here

I'm quit interested to see what the Mathematica community thinks is the best technique for specifying which arguments should be File Buttons and if it might be possible to incorporate the File buttons with Template Completion. My current code is below, which isn't generalized to all function definitions, but I knew it would be best to attempt to create a partially working solution. I used the following question to help piece a together my partially working example.

MakeBoxes[replacementMarker[a_, tag_], StandardForm] ^:= 
  TagBox[MakeBoxes[a], tag];

 replaceMark[rule_, nb_: EvaluationNotebook[], which_: All, 
   cell_: EvaluationCell] := (
   SelectionMove[nb, which, cell]; 
    NotebookRead[EvaluationNotebook[]] /. rule]
   ) ;

  BoxData[RowBox[{"Test", "[", 
           file = SystemDialogInput["FileOpen"];
           TagBox[_, "replaceThis"] :> "\"" <>
             StringReplace[file, "\\" -> "\\\\"]
             <> "\""
          ], "replaceThis"]
       , ",", 
            "Placeholder"]}], "]"}]]
  , "Output"]
share|improve this question
there is some code here… in which you press a button and the button is replaced by text. You may be able to hack that around to do what you want for this task. – Mike Honeychurch Jul 18 '13 at 3:56
I copied your code into the question. It's not excessively long, and I think it is better to have it here than linked exclusively. – Mr.Wizard Aug 17 '13 at 16:54
up vote 1 down vote accepted

I'd start with something like this:

file = Button["File", file = SystemDialogInput["FileOpen"]];
CellPrint@ExpressionCell[test[Dynamic@file, Placeholder[text]], "Input"]
share|improve this answer

Your Answer


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.