0
$\begingroup$

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.

$\endgroup$
  • $\begingroup$ You can drag the file onto the notebook window to insert its contents at the cursor position (this works with most file formats) $\endgroup$ – Lukas Lang Jan 10 at 11:16
  • $\begingroup$ 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... $\endgroup$ – Theo Tiger Jan 11 at 9:50
  • $\begingroup$ 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.. $\endgroup$ – Nicola Jan 16 at 12:27
3
$\begingroup$

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

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

enter image description here

$\endgroup$
  • $\begingroup$ It's a good proposal, but I think that with a long list it will become messy, isn't it? $\endgroup$ – Nicola Jan 10 at 12:01
  • $\begingroup$ @Nicola If you have a cleaner solution in mind, just let us know. $\endgroup$ – Kuba Jan 10 at 14:00
  • $\begingroup$ 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. $\endgroup$ – Nicola Jan 10 at 14:47
  • $\begingroup$ 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. $\endgroup$ – Nicola Jan 10 at 18:06
  • $\begingroup$ 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. $\endgroup$ – Theo Tiger Jan 11 at 9:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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