Please consider the following:
I have created a GUI where I can choose the path of a notebook (which I need for later calculation) via
FileNameSetter[Dynamic[path1], "Open", {"Mathematica Notebook" -> {"*.nb"}}]
Now I would like Mathematica to evaluate the chosen notebook immediately after setting the path.
Has anyone an idea?
Answer
I suspect there might be an easier way to do this, but you might use a variation of this example:
Module[{nb},
Button["Find and run",(
path1 = SystemDialogInput["FileOpen"];
nb = NotebookOpen[path1, Visible -> False];
SelectionMove[nb, All, Notebook];
SelectionEvaluate[nb];
NotebookClose[nb];
)]]
Update:
I initially couldn't get NotebookEvaluate[]
To work inside a button, which led me to just use the method above, however a quick search and I found this answer by celtschk: How do I make NotebookEvaluate work inside Button? which means you can simplify the above and just have:
Button["Find and run",
NotebookEvaluate[path1 = SystemDialogInput["FileOpen"]]
,Method -> "Queued"]
Comments
Post a Comment