Opening a .root file using Mac OS X Finder

I’m working with a various histograms and have already installed the Mac OS X QuickLook and Spotlight plugins, but I’m wondering if its possible to to open a root file from Finder and have it open in a root instance in the terminal. For example, open a terminal window with the ‘root my_rootfile.root’ command executed just be double clicking the file. Any ideas?

This is possible but I’ve not yet implemented it, i.e. it involves making a ROOT.app bundle that executes root.exe in a terminal via apple script. To be done.

Cheers, Fons.

[quote=“rdm”]This is possible but I’ve not yet implemented it, i.e. it involves making a ROOT.app bundle that executes root.exe in a terminal via apple script. To be done.
[/quote]

Any chance this ever got done? I can’t find a ROOT.app and I am not being able to make my own wrapper with PyROOT (launching a TBrowser).

Any updates?

I would also be interested in this…

I have no idea about MacOS, but here is how to do it under KDE (works basically the same under Microsoft Windows, so I hope it might also be similar in MacOS?)

Go to System Settings -> Applications -> File Associations. (names will be different on other OS)
Then add a new file association for *.root files. It should look like the following:

The openroot.sh linked here sets up the ROOT environment and then starts root with file as parameter. For Linux, it looks like this:

#!/bin/bash
oldDir="$(pwd)"
cd path/to/root
. bin/thisroot.sh
cd "$oldDir"

# Option 1
# root -l "$1"

# Option 2
# root -l /path/to/open.C'("'$1'")'

If you choose option 1 (uncomment the corresponding line), you are done.

Choose Option 2 if you like to open a TBrowser automatically. You call a simple open.C macro that looks like this:

#include <TFile.h>
#include <TBrowser.h>

void open(const char *fn) {
    TFile::Open(fn);
    new TBrowser;
}

(Advantage to rootbrowse is that you can actually use root, no crippled command line saying “Enter to exit”)

I hope this helps! If you google for “file association mac os” you will probably find how to do it on MacOS.

1 Like

I believe the earlier poster is correct that there needs to be some sort of .app bundle for macOS to be able to open files from Finder. As far as I know, the analogue in macOS for what you’ve described is the “Open with…” dialogue in Finder, which does not accept .sh files as an option, as far as I can tell.

I wrote the following script which you can copy in the Automator>File>New>Application>Run Shell script (search that on the search bar). Make sure you select pass input as arguments

Spaces are represented by “_”

osascript -e "
_tell application “Finder”
__set myWin to window 1
__set thePath to (quoted form of POSIX path of (target of myWin as alias))
__tell application “Terminal”
___activate
___tell window 1
_____set currentTab to do script “cd " & thePath
_____delay 1
_____do script “root -l” in currentTab
_____delay 1
_____do script “’“new TBrowser”’” in currentTab
___end tell
__end tell
_end tell”

and save as ROOT.app or whatever you want to name it in Application directory

Get info for the .root file you want to open and select ROOT.app as the default application and click on change all.

Done :slight_smile:

1 Like