MathGroup Archive 2008

[Date Index] [Thread Index] [Author Index]

Search the Archive

An interface function for adding Trusted Paths

  • To: mathgroup at
  • Subject: [mg86131] An interface function for adding Trusted Paths
  • From: David Reiss <dbreiss at>
  • Date: Mon, 3 Mar 2008 04:38:50 -0500 (EST)

Hi All,

When creating a general system in Mathematica like A WorkLife
FrameWork ( I often need to process
multiple notebooks to gather data from those notebooks to distill and
present to the user. Often I open these notebooks with the option
Visible->False so that the user doesn't see them opening and closing
as the processing takes place.  But if those notebooks have dynamic
content in them then, each time they are opened (even if invisible), a
dialog will open asking if the user gives permission for dynamic
content to be evaluated.  This is a very good feature--it is key to
security in a system that allows automatic evaluation of dynamic
content that can access the operating system.  Mathematica allows you
to mark a directory as "Trusted" and, if so marked, opening notebooks
from a trusted directory will not prompt the permission dialog.

The interface in Mathematica for adding a new directory to the list of
trusted directories is not very user friendly at the moment (it
involves knowing how to edit FrontEnd`FileName expressions) and so I
have created a function that does this in a way that is more intuitive
in that it simply prompts you to select a directory from the standard
file system Open dialog.

In fact, in A WorkLife FrameWork, there are a very large number of
features that make underlying functionality of Mathematica much more
useful; hence the tagline for the product: "Extending Mathematica's
Reach..."  You can download the fully functional trial version of A
WorkLife FrameWork from

Here is the code that defines a function AddTrustedPath that presents
the more useful interface to taking this action (note that, as it
should, it still opens a dialog at the end that will ask for
confirmation that you do indeed want to add the directory that you
choose).  A set of functions like this (also ones for adding untrusted
paths, for example) are currently in the Development version of A
WorkLife FrameWork:


AddTrustedPath::nottrusted =
  "The directory `1` is currently contained in the list of Untrusted \
directories.  Please remove it from this list first before adding it
to the \
list of Trusted directories.";

AddTrustedPath[] :=

 Catch@Module[{securityOptions, dir, trustedPaths, unTrustedPaths,
    unTrustedPathsAsStrings, trustByDefault},

   trustedPaths =
    CurrentValue[$FrontEnd, {"NotebookSecurityOptions",

   unTrustedPaths =
    CurrentValue[$FrontEnd, {"NotebookSecurityOptions",

   unTrustedPathsAsStrings = ToFileName[{#}] & /@ unTrustedPaths;

   trustByDefault =
    CurrentValue[$FrontEnd, {"NotebookSecurityOptions",

   dir = SystemDialogInput["Directory", $HomeDirectory,
     WindowTitle -> "Select a Directory to Trust"];

   If[dir === $Canceled, Throw[$Canceled]];

   If[MemberQ[unTrustedPathsAsStrings, dir],
    Throw[Message[AddTrustedPath::nottrusted, dir];
     (SetOptions[$FrontEnd, "PreferencesSettings" -> {"Page" ->

   trustedPaths =
    Union@Flatten[{trustedPaths, FrontEnd`FileName[{#}] &[dir]}];

   securityOptions = {
     "TrustedPath" -> trustedPaths,
     "UntrustedPath" -> unTrustedPaths, "TrustByDefault" ->

   SetOptions[$FrontEnd, "NotebookSecurityOptions" ->


This code is also available as a downloadable notebook from the
WorkLife FrameWork Blog at

I hope that this is useful to folks!  Just remember that there are a
huge number of things like this in A WorkLife FrameWork and more in
development...  Give it a try:

  • Prev by Date: how insert hyperlink to doc paclet in ordinary notebook?
  • Next by Date: Re: Re: Mathematica 6 obtains imaginary eigenvalues for a Hermitian
  • Previous by thread: Re: how insert hyperlink to doc paclet in ordinary notebook?
  • Next by thread: Re: Changing the positions of limits on displayed mathematical