I want to get a file once and only once at the start of a coding session. Then, whenever I save the file in the Wolfram Workbench, have it be gotten automatically. How can I construct such a utility?

  • 1
    $\begingroup$ Could you be a bit more specific? "Gotten" how/what/where? $\endgroup$
    – Mr.Wizard
    Jun 26, 2012 at 5:31
  • $\begingroup$ If I understand correctly you want to load your source files into the Mathematica session automatically (as if using Get in the notebook), right? This is controlled by the "Notebook Properties" and "Source Properties" settings, which you can access from the context menu entry "Properties" (at least it works this way with eclipse+workbench plugin) $\endgroup$
    – sebhofer
    Jun 26, 2012 at 8:07

2 Answers 2


When you create an Application project in Wolfram Workbench named for example Test, a Test\Test.m file is created that is loaded everytime you save a file in the project, ie. a Get is applied to this file. By default the Execution Build Command in the project's properties will be something like this

<< Test`

This command will look in the file Test\Kernel\init.m which contains something like


So the file to look at is located in the file Test\Test.m

A typical package located at Test\Folder1\package1.m looks like this (notice the BeginPackage instruction).

BeginPackage["Test`Folder1`package1`",{(*contexts this package depends on*)}]
(* Exported symbols added here with SymbolName::usage *)  

f::usage = "f[x] returns the square of x.";

Begin["`Private`"] (* Begin Private Context *) 

f[x_] := x^2;

End[] (* End Private Context *)


What I do in order to have its definitions automatically reloaded in the Kernel when I save it is the following.

I have a list contexts before the package definition of Test.m and I manually Get all the contexts in this list so that they also are gotten when I save a file in the project while Mathematica is running and linked to Eclipse.

The Test\Test.m package looks like this



(* Exported symbols added here with SymbolName::usage *)  

Begin["`Private`"] (* Begin Private Context *) 

End[] (* End Private Context *)


This way of doing has the advantage that you only need to do


in order to load several related packages of a same application exported in \$BaseDirectory\Applications (or $UserBaseDirectory\Applications).

For modifying $BaseDirectory for example you have to define an environment variable. See here Mathematica Sessions.

Something practical is also to define the current Directory to a directory of the project using for example for the directory Test\Folder1 before << Test` in the Execution Build Command


This way you can save outputs by default to a folder you chose.


One way would be to both Get[] the file and get the file-date when loading it, then dynamically checking the date to see if the file was updated.

So just for readability I define a function to get the date, and a function which will update an expression when the file date changes.

fileDate[filePath_] := Date/.(FileInformation@filePath)

fileUpdate[exp_,filePath_] := 

So then you'd get the file writing:

 a = Get[filePath]; currentFileFrom = fileDate[filePath];
 Dynamic[fileUpdate[a = Get[filePath], filePath], UpdateInterval -> 1]

It would be preferable to put this into the dynamicexpression of the notebook, however since IO doesn't tricker dynamic updating we need the update interval for the checking, This is done by calling:

NotebookDynamicExpression -> 
      Dynamic@Refresh[fileUpdate[a = Get[filePath], filePath], UpdateInterval -> 1]]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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