7
$\begingroup$

I am new to Mac OS, so this might be a silly question, but....

I just searched for $BaseDirectory and $UserBaseDirectory in my Mac OS El Captain, using the Finder. Neither directory is present apparently. For example, searching for

/Users/Alessandro/Library/Mathematica

I cannot find the Library directory. Similar problem with

/Library/Mathematica

I can find the Library directory, but there is no Mathematica directory inside.

In Windows, the analogous directories are hidden. Is this the same in Mac OS too? If yes, how can I see them?

$\endgroup$
6
  • 3
    $\begingroup$ Don't know about Mac OS but what about SystemOpen @ $UserBaseDirectory? $\endgroup$
    – Kuba
    Commented Mar 7, 2016 at 20:26
  • 3
    $\begingroup$ They are hidden. You can tell Finder to show hidden files and folders by entering a specific command in the Terminal: defaults write com.apple.finder AppleShowAllFiles YES and then relaunch the Finder. You can also use Mathematica's SystemOpen command to access them, as @Kuba suggested. $\endgroup$
    – Stefan R
    Commented Mar 7, 2016 at 20:47
  • $\begingroup$ The directories you mention are not on in the usual places for $UserBaseDirectory and $BaseDirectory OS X. Did you do some kind of custom install? For instance, $BaseDirectory is usually /Library/Mathematica and this directory is not hidden in Yosemite. (I have not upgraded to El Capitan. $\endgroup$
    – m_goldberg
    Commented Mar 8, 2016 at 0:26
  • $\begingroup$ @m_goldberg No custom install, I edited the paths and their status. I ultimately solved the problem following Kuba advice. But I first tried Stefan's trick (also found online): /Users/Alessandro/Library becomes visible but cannot be opened, while /Library/Mathematica simply does not exist. All in all the only reasonable solution seems to be Koba's SystemOpen one. All this is not easily found in the documentation. I am a bit disappointed by WRI. What is the point in making these important directories so hard to reach? $\endgroup$
    – magma
    Commented Mar 8, 2016 at 9:44
  • 1
    $\begingroup$ SystemOpen[$BaseDirectory] returns $Failed: i'm using Mathematica 12.0 and macOS 10.15.4 $\endgroup$
    – Valerio
    Commented Apr 22, 2020 at 17:02

4 Answers 4

8
$\begingroup$

Ok, so the quick way to find given directory is just to use SystemOpen @ dir. E.g.

 SystemOpen @ $UserBaseDirectory

I go there all the time so I added a menu to the main menu in order to not write this each time. Here's the procedure:

   (*aux function*)
dir = FileNameJoin[{ #, "SystemFiles", "FrontEnd", "TextResources",
    $OperatingSystem /. "MacOSX" -> "Macintosh"}] &;

   (*we are going to play inside $UserBaseDirectory to not break installation*)
   (*not everything from $ID is present in $USB so let's create that directory and file if that's necessary*)
If[Not @ DirectoryQ @ #, 
  CreateDirectory[#, CreateIntermediateDirectories -> True]
] & @ dir @ $UserBaseDirectory;

CopyFile[
  FileNameJoin[{dir@$InstallationDirectory, "MenuSetup.tr"}],
  FileNameJoin[{dir@$UserBaseDirectory, "MenuSetup.tr"}]
];

SystemOpen @ FileNameJoin[{dir@$UserBaseDirectory, "MenuSetup.tr"}]

Now you have to add the menu anywhere you find it handy:

Menu["Locations", 
    {

        MenuItem["$UserBaseDirectory", KernelExecute[ 
          SystemOpen[ $UserBaseDirectory] ], MenuEvaluator -> "System" ],
        MenuItem["$InstallationDirectory", KernelExecute[ 
         SystemOpen[ $InstallationDirectory] ], MenuEvaluator -> "System" ],
        MenuItem["$TemporaryDirectory", KernelExecute[ 
         SystemOpen[ $TemporaryDirectory] ], MenuEvaluator -> "System" ],
        MenuItem["NotebookDirectory[]",  KernelExecute[  
            If[
                ReplaceAll["FileName", NotebookInformation[SelectedNotebook[]]] =!=  "FileName", 
                SystemOpen[ NotebookDirectory[ SelectedNotebook[] ] ]
            ]], 
            MenuEvaluator -> "System"
        ]

    }],

Don't miss any comma etc. Save, restart MMA and be happy:

enter image description here

$\endgroup$
5
  • $\begingroup$ Great answer! Thanks $\endgroup$
    – magma
    Commented Mar 10, 2016 at 2:35
  • $\begingroup$ This is useful code $\endgroup$
    – ktm
    Commented Jan 5, 2018 at 22:50
  • $\begingroup$ @user6014 I'm glad it helps :) $\endgroup$
    – Kuba
    Commented Jan 6, 2018 at 11:34
  • $\begingroup$ @Kuba: This may not work properly in upcoming Mathematica releases. (That a version 12 is on the way is no secret: In his frequent Twitch live-streaming "CEOing", he repeatedly refers to version 12.) Can you PM me to discuss this, since it's inappropriate to publicly deal with it right now? You'll find my email address at my web page math.umass.edu/directory/emeritus-faculty/murray-eisenberg. $\endgroup$
    – murray
    Commented Nov 14, 2018 at 1:20
  • $\begingroup$ @murray it's 4 am here so I will contact you as soon as I hit the office later in the morning. $\endgroup$
    – Kuba
    Commented Nov 14, 2018 at 2:45
4
$\begingroup$

On OS X, ~/Library is hidden by default (despite its name not starting with .). You can open it by clicking Go in the menu bar (Finder), then holding down the Option key. As soon as you press Option, Library appears in the list of locations you can "go to".

You can also hit Command-Shift-G in the Finder then type the path manually (or with Tab-completion) and hit Return. The location will be opened in the Finder even if it is hidden.

$\endgroup$
1
  • $\begingroup$ Good things to know, thanks $\endgroup$
    – magma
    Commented Mar 10, 2016 at 2:33
2
$\begingroup$

In neither Wolfram Desktop nor Mathematica Home Edition does $BaseDirectory reference a directory/folder that exists on El Capitan.

Mathematica references /Library/Mathematica Wolfram Desktop references /Library/Wolfram Desktop

I am not sure, yet perhaps this is a defect caused by a missing tilde '~' which would you would expect to be expanded to reference the User domain aka ~/Library/Mathematica expanding to "/Users/foo/Library/Mathematica".

The short solution is to substitute $UserBaseDirectory in place of $BaseDirectory or, perhaps to reference the Application package itself /Applications/Mathematica.app/Contents/SystemFiles

I ran into the same problem while trying to figure out why my importer for Apple Mail emlx files must be explicitly referenced while calling Import rather than automatically loading as the documentation says it should.

EDIT: My answer concerns version 11. I have yet to verify that this case exists on 9 or 10

EDIT: Contrary to what others indicate, this is not an OS X issue. Mathematica 11 Home and Wolfram Desktop 11 references a Folder that does not exist, so clearing the 'hidden' attribute does nothing.

$\endgroup$
1
  • $\begingroup$ I have the same problem. I cannot see (nor via SystemOpen access) $BaseDirectory (/Library/Mathematica), even though I can see hidden folders in Finder. MacOS Sierra 10.12.6, Mathematica 11.2.0. $\endgroup$ Commented Sep 24, 2017 at 9:11
2
$\begingroup$

Regarding the fact that SystemOpen[$BaseDirectory] returns $Failed, I contacted the Wolfram Technical Support and the answer is:

$BaseDirectory is normally for machines that are shared by several users so if you are the only user on the machine who uses Mathematica, then it's highly likely the directory won't exist.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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