# How to load mx file on current notebook with double click on them

I would like to load a mx file into the current notebook just by double click on it.

In short, a have a long list of mx files, I want to load some of them and evaluate some cells of a notebook. I don't want to automatize the loading and evaluation with a file list (f.i. with a for loop), but at the same time I would like to find a quicker alternative to copy/paste the file name and then load it from a cell.

Reading Detecting double click events I think it is possible to associate the loading with a double click, but I am not familiar with event handler and I don't know how to get the file name that is pointed by the mouse).

I thought to set the "Open with" options to open the mx file with Wolfram Mathematica but it doesn't seem to work.

• You can drag the file onto the notebook window to insert its contents at the cursor position (this works with most file formats) – Lukas Lang Jan 10 '19 at 11:16
• Are you asking for a way to import the mx file from the shell, like Windows Explorer, or from within Mathematica? It occurs to me that you are asking for the former, which contradicts with your reference to EventHandlers in Mathematica... – Theo Tiger Jan 11 '19 at 9:50
• You are right @TheoTiger, probably MM's EventHandlers is not necessary. I have thought about this solution: what if I define a wls script "LoadMX" and I associate to mx files with Windows Explorer. The script simply loads the file whose name is passed (somehow) in one of the arguments when it is called from the shell when double clicking on the file. Unfortunately, I have don't know if this idea is correct and how to implement this.. – Nicola Jan 16 '19 at 12:27

## 1 Answer

An elegant way to do one-click importing might be:

TableForm[
With[{filename = #}, {Button["Load", Get[filename] &], FileNameTake@#}
] & /@ FileNames["*.mx", {"/my/directory"}]
]


• It's a good proposal, but I think that with a long list it will become messy, isn't it? – Nicola Jan 10 '19 at 12:01
• @Nicola If you have a cleaner solution in mind, just let us know. – Kuba Jan 10 '19 at 14:00
• I didn't mean to be rude, I am just saying that the solution isn't what I asked, one reason being because with a long list it will become messy. – Nicola Jan 10 '19 at 14:47
• In my notebook the solution seems to work only if I run twice the cell. If I run it once and then I click on the button it is not loading. – Nicola Jan 10 '19 at 18:06
• Please check whether the file is really not loaded, or if the FrontEnd just has not realized the loading yet (i.e., syntax highlighting has not been updated). Try to evaluate a symbol which is supposed to be loaded after clicking Load once. – Theo Tiger Jan 11 '19 at 9:47