Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2008

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

Search the Archive

An interface function for adding Trusted Paths

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

Hi All,

When creating a general system in Mathematica like A WorkLife
FrameWork (http://scientificarts.com/worklife) 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 http://scientificarts.com/worklife/trial.html

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:



ClearAll[AddTrustedPath];

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",
"TrustedPath"}];

   unTrustedPaths =
    CurrentValue[$FrontEnd, {"NotebookSecurityOptions",
"UntrustedPath"}];

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

   trustByDefault =
    CurrentValue[$FrontEnd, {"NotebookSecurityOptions",
"TrustByDefault"}];

   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" ->
"System"}];
      FrontEndTokenExecute["PreferencesDialog"])]];

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

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

   SetOptions[$FrontEnd, "NotebookSecurityOptions" ->
securityOptions];

   securityOptions
   ]

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

http://scientificarts.com/worklife/wlfwblog/BE3413476880/BE3413476880.html


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: http://scientificarts.com/worklife/trial.html


  • 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