5
$\begingroup$

I would like to use the Windows Task Scheduler, or Visual Cron, to start a Mathematica notebook or .m file to do some system maintenance tasks: copy files from one place to another, etc. How do I set up the notebook/file so it will execute when started without asking any questions?

I answered this question myself here.

$\endgroup$
5
  • 6
    $\begingroup$ I'll add an obligatory "Mathematica is the wrong tool for this job" note. Also, AFAIK, it doesn't preserve/you can't modify file permissions when copying from one place to another natively — something I consider very critical when it comes to system maintenance tasks (maybe not for what you have in mind). $\endgroup$
    – rm -rf
    Commented Jul 1, 2013 at 19:39
  • 1
    $\begingroup$ I use Mathematica in notebook form to do this kind of thing and it works nicely. It's easy to use FileNames, Select, Union, Complement, StringReplace, etc. to handle the logic of what I want to implement. I don't need to change the file permissions. $\endgroup$ Commented Jul 1, 2013 at 19:46
  • $\begingroup$ Perhaps useful: mathematica.stackexchange.com/q/9936/131 $\endgroup$
    – Yves Klett
    Commented Jul 1, 2013 at 20:33
  • $\begingroup$ I suppose Run will always enable you to fill in the gaps. $\endgroup$ Commented Jul 2, 2013 at 18:34
  • $\begingroup$ I've just found this are you familiar with this? It seems it is all you need. $\endgroup$
    – Kuba
    Commented Aug 5, 2013 at 11:00

2 Answers 2

3
$\begingroup$

I can't help with the Windows part it, but I would imagine this is a two step operation. First, invoke Mathematica -- which you can do form the command line (or cron, presumably), as shown by the instructions here, and have Mathematica open the desired notebook.

Once started, you can ensure that the commands will be run by using initialization cells, which automatically evaluate when the notebook is opened. Instructions for that are here.

$\endgroup$
1
  • $\begingroup$ This is helpful. Lot's of little details to work out here. I'll post what I end up doing. In the meantime, if anyone has anything to add, I be grateful. I'm surprised that this isn't routine. $\endgroup$ Commented Jul 2, 2013 at 17:50
1
$\begingroup$

I hope someone will post here an answer based on InitializationCells because I wasn't able to make them work for me.

This is quick walkaround:

DynamicModule[{},
          Framed["dir created"]
          , Initialization :> (   
CreateDirectory[FileNameJoin[{"C:", "Users", "Kuba", "Desktop", "dir1"}]];
CreateDirectory[FileNameJoin[{"C:", "Users", "Kuba", "Desktop", "dir2"}]];
 )
]

Evaluate this code (Probably You will have to change "Kuba" in path :)). Save it in trusted directory. Create task via Windows Task Scheduler to open this file.

Works for me.

Big disadvantage is that You have to evaluate code with all procedures.

Quick solution Put conditional construct in Initialization of this DynamicModule. It can check if there is directory called "ENABLED" in it's directory. There will not be such during first evaluation. Create manually directory "ENABLED" after saving main notebook.

$\endgroup$

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