# Set the default folder to be that of the notebook?

Posted 10 months ago
1940 Views
|
7 Replies
|
7 Total Likes
|
 My system: Mathematica 11.2, Windows 10The problem: I want to configure my Mathematica system to save all graphics to the folder of the current notebook. Currently the default folder seems to be whatever folder was used the last time.Caveat: I don't know what the various pieces of software do for me. I did all my programming in DOS-era, and the distinction between Mathematica-kernel and the FrontEnd/GUI is blurry for me.I asked for help in the appropriate StackExchange forum. There the useful suggestion to give the command SetDirectory[NoteBookDirectory[]] was given. While helpful, this is unsatisfactory, for apparently it only affects the default output folder of an Export-command. My uneducated guess is that the mouse action in "Save Graphics As" does not touch the kernel, and it is thus blissfully unaware of the above command. On the other hand, the Export-command is affected by that. How can I configure the mouse interface (the FrontEnd??) to also use the folder of the current notebook as the default folder for saving graphics? Why isn't the folder of the notebook NOT the default folder for the mouse action of "save graphics as"?
7 Replies
Sort By:
Posted 10 months ago
 Maybe the directory for saving through the FrontEnd is handled by the operating system, not by Mathematica. Just a guess.
Posted 10 months ago
 I believe Gianluca is right on this one. I have had similar experiences in other environments.
Posted 10 months ago
 First, let me offer a practical solution: instead of changing Mathematica's behaviour, define a function that will do this for you. export[file_String, rest___] := Export[FileNameJoin[{NotebookDirectory[], file}], rest]  What you ask (i.e. that programmatic exporting goes to the notebook's directory by default) is not reasonable, as it is not compatible with how Mathematica (and all comparable programs) work. It breaks a fundamental analogy/metaphor/concept (whatever you want to call it) that helps us think about file system organization. Mathematica, like basically everything other similar system, uses the concept of a "current directory". You can think of the filesystem as a "space" that you move through. The current directory is where you are standing right now. Anything do you happens here.Notebooks are not isolated from each other. It makes no difference which notebook you are running code in. They all see the same system state (i.e. kernel state). Thus they all share the same working directory. The "Mathematica kernel" is the program that does all the computation and holds the system state. If you define a variable or function, they live in the kernel process's memory. Normally, there is one kernel running, shared by all notebooks. It is the kernel where your work lives and where your program runs, so it is the kernel that defined "where you are located" in the filesystem.You could start a different kernel for each notebook, but you would soon run out of licenses. This would also prevent any sharing of information between notebooks. If a variable is defined in one notebook, it will not be visible in another. Of course, all this does not mean that there are no practical workarounds to exporting to the same directory where the notebook is saved: see the export function at the beginning of my post. Clearly, wanting to do this is reasonable and useful.
Posted 10 months ago
 My uneducated guess is that the mouse action in "Save Graphics As" does not touch the kernel, and it is thus blissfully unaware of the above command. I'm sorry, I misunderstood what you were asking, but I cannot delete the previous post.What you say above is correct.I don't know how to change the default location for "Save As..."
Posted 10 months ago
 No problem, Szabolcs. Thanks for your time. What happens when there are several programs running simultaneously is a bit fuzzy to me, so I was unable to phrase my question clearly. Should I have posted this somewhere else, where people responsible for the development of the FrontEnd can see it?
 You can use the following to temporarily reset the default directory for the dialog: CurrentValue[\$FrontEndSession, "NotebookBrowseDirectory"] = NotebookDirectory[EvaluationNotebook[]] IIRC, this only works on Windows and Linux. Mac's behavior is baked into the system.