Skip to main content

front end - Programmatically quitting the FrontEnd or running without one?


I have a conundrum.


I use an iMac's OS X 10.6.8 settings to start and stop the machine at the specific times that I need a particular notebook to run. I've done this because it has worked more reliably then timed events. Mathematica launches automatically when my computer boots and the notebook with all its cells set as Initialization Cells launches automatically and evaluates when Mathematica starts.


The last expression in the notebook:


NotebookSave[]



as evident, saves this active notebook. I need this because some graphics in the notebook change and I want to review them later.


This notebook will be the only open notebook at the time of its evaluation.


So far so good.


Now I want the notebook to programmatically quit the Mathematica FrontEnd.


This gets tricky and presents (at least) 2 problems:


Problem 1:


NotebookSave[]
FrontEndTokenExecute["FrontEndQuit"]

begins the process, but gives me the following popup window:



popup window


This doesn't help me, because I want this to run on its own and as stated above I have an OS setting that will shut down the computer soon after Mathematica would quit.


I won't have anyone in front of the computer to click "OK" and thereby allow the shutdown to proceed. No click no shutdown.


Problem 2:


All of the notebooks cells, including the one with the:


   FrontEndTokenExecute["FrontEndQuit"]

set as Initialization Cells presents another problem. IF I can find a work-around for the popup warning above, I still need a way to break, abort, or interrupt the flow of control so I don't have a notebook, which will always open, evaluate, then quit Mathematica. At some point I'll want it to stay open to edit or change the code.


I've looked at variations of:


NotebookSave[]

Interrupt[];
FrontEndTokenExecute["FrontEndQuit"]

They give me a popup window like this:


interrupt window


Pressing "Continue" or "Abort" just gives me the same popup window ("The notebook ..... contains a running evaluation...." as I had in "Problem 1".




If my solution in doing this includes automatically opening and evaluating the notebook I think I need some way to have a button or popup window come up which gives me a period of time, say 30 seconds to abort the closing of the application and its notebook. If no one aborts the process before 30 seconds I'd want the machine to shut down.





  • Is such a thing even possible given what I've found above?




  • Do I need to consider dispensing with the FrontEnd for this altogether? If yes, can someone point me in the right direction? At least for now I'd feel content if I can rely upon the OS to boot and shut down the computer so I guess I could launch the code when the computer boots. This way I wouldn't need to worry about recurring timers, that to date have proven unreliable.




The notebook in question does a lot of different stuff: opening parallel kernels, lots of parallel mapping, creating graphics, and emailing results both text and graphics. Is it even feasible for this kind of complication to run as a script on booting of the computer?


Stumped and looking for some guidance.


Thanks.



Answer




An idea on how to use osascript (as also suggested by sebhofer in a comment to the question): with Mathematica running, execute


osascript  -e 'tell application "Mathematica" to quit'

in a shell. It quits Mathematica completely. If there are unsaved notebooks, Mathematica pops up a dialog, so make sure everything is saved before doing that.


To be able to schedule this from a high level (ie from a GUI) you can write an Applescript containing tell application "Mathematica" to quit:


Mathematica graphics


and create a calendar event to run this whenever you want. Or, at least, you can if you are not running OS X 10.8, as Apple appear to have removed this ability in the latest version (you can still use launchd, for instance).


Comments

Popular posts from this blog

plotting - Plot 4D data with color as 4th dimension

I have a list of 4D data (x position, y position, amplitude, wavelength). I want to plot x, y, and amplitude on a 3D plot and have the color of the points correspond to the wavelength. I have seen many examples using functions to define color but my wavelength cannot be expressed by an analytic function. Is there a simple way to do this? Answer Here a another possible way to visualize 4D data: data = Flatten[Table[{x, y, x^2 + y^2, Sin[x - y]}, {x, -Pi, Pi,Pi/10}, {y,-Pi,Pi, Pi/10}], 1]; You can use the function Point along with VertexColors . Now the points are places using the first three elements and the color is determined by the fourth. In this case I used Hue, but you can use whatever you prefer. Graphics3D[ Point[data[[All, 1 ;; 3]], VertexColors -> Hue /@ data[[All, 4]]], Axes -> True, BoxRatios -> {1, 1, 1/GoldenRatio}]

plotting - Filling between two spheres in SphericalPlot3D

Manipulate[ SphericalPlot3D[{1, 2 - n}, {θ, 0, Pi}, {ϕ, 0, 1.5 Pi}, Mesh -> None, PlotPoints -> 15, PlotRange -> {-2.2, 2.2}], {n, 0, 1}] I cant' seem to be able to make a filling between two spheres. I've already tried the obvious Filling -> {1 -> {2}} but Mathematica doesn't seem to like that option. Is there any easy way around this or ... Answer There is no built-in filling in SphericalPlot3D . One option is to use ParametricPlot3D to draw the surfaces between the two shells: Manipulate[ Show[SphericalPlot3D[{1, 2 - n}, {θ, 0, Pi}, {ϕ, 0, 1.5 Pi}, PlotPoints -> 15, PlotRange -> {-2.2, 2.2}], ParametricPlot3D[{ r {Sin[t] Cos[1.5 Pi], Sin[t] Sin[1.5 Pi], Cos[t]}, r {Sin[t] Cos[0 Pi], Sin[t] Sin[0 Pi], Cos[t]}}, {r, 1, 2 - n}, {t, 0, Pi}, PlotStyle -> Yellow, Mesh -> {2, 15}]], {n, 0, 1}]

plotting - Mathematica: 3D plot based on combined 2D graphs

I have several sigmoidal fits to 3 different datasets, with mean fit predictions plus the 95% confidence limits (not symmetrical around the mean) and the actual data. I would now like to show these different 2D plots projected in 3D as in but then using proper perspective. In the link here they give some solutions to combine the plots using isometric perspective, but I would like to use proper 3 point perspective. Any thoughts? Also any way to show the mean points per time point for each series plus or minus the standard error on the mean would be cool too, either using points+vertical bars, or using spheres plus tubes. Below are some test data and the fit function I am using. Note that I am working on a logit(proportion) scale and that the final vertical scale is Log10(percentage). (* some test data *) data = Table[Null, {i, 4}]; data[[1]] = {{1, -5.8}, {2, -5.4}, {3, -0.8}, {4, -0.2}, {5, 4.6}, {1, -6.4}, {2, -5.6}, {3, -0.7}, {4, 0.04}, {5, 1.0}, {1, -6.8}, {2, -4.7}, {3, -1....