First, note that turning off messages is technically not the same thing as not printing them. You can avoid printing messages by removing the output channel they're being sent to:
$Messages = {}
Restore the previous behaviour using $Messages = $Output
, provided that you haven't changed $Output
.
But this won't turn messages off, it will only avoid printing them. Here's the transcript for one particular example which shows the effect of turning off messages, as opposed to not printing them:
In[1]:= boo::mess = "Boo message"
Out[1]= "Boo message"
In[2]:= boo[] := (Message[boo::mess]; 1)
In[3]:= boo[]
During evaluation of In[3]:= boo::mess: Boo message
Out[3]= 1
In[4]:= Check[boo[], "error"]
During evaluation of In[4]:= boo::mess: Boo message
Out[4]= "error"
In[5]:= Off[boo::mess]
In[6]:= Check[boo[], "error"]
Out[6]= 1
In[7]:= On[boo::mess]
$Messages = {};
In[9]:= Check[boo[], "error"]
Out[9]= "error"
(Make sure that you evaluate these as separate inputs (cells). Some only have an effect on subsequent inputs, but not on separate code within the same input.)
Notice that turning off the message had an effect on Check
, but simply preventing printing it did not. It has effects on various other documented and undocumented parts of Mathematica as well, such as the debugging tools ("Break on messages" feature).
Quiet[expr]
does actually prevent the messages generated by expr
from reaching any code outside of the Quiet[...]
, just like turning Off
the messages.
Here's a different idea: if your program is written in a script (.m
file), then you can run it on a single input line using Get
. This means that you can capture all generated messages with $MessageList
. Then you can create a message group
for them which will allow you to easily toggle them using Off
and On
. If a new, unexpected message shows up at some point, it will still get printed, which might be good or bad depending on your application.
Quiet
isn;t what you are looking for. Do you mean that you want the first message displayed but then no others? Can you please clarify. $\endgroup$$Messages = {}
. $\endgroup$