I'm running Mathematica on OS X and I want to create an Automator action that converts spreadsheet files. I have written this script:

#!/usr/local/bin/MathematicaScript -script

FORMATS = {"csv", "tsv", "dat", "xls", "xlsx", "odf"};
files = Rest @ $ScriptCommandLine;
data = Import /@ files;
{ext, delete} = 
   DialogNotebook @ {
     TextCell["Choose output format:"], 
     PopupMenu[Dynamic[x], FORMATS], 
     Row @ {Checkbox[Dynamic[y]], TextCell["Delete original files"]}, 
     Row @ {CancelButton[], DefaultButton[DialogReturn[{x, y}]]}
newNames = (FileNameJoin@{DirectoryName[#], FileBaseName[#]} <> "." <> ext)& /@ files;  
MapThread[Export, {newNames, data}];
If[delete, DeleteFile[files]];

When I run it, I get this error message when running DialogInput:

FrontEndObject::notavail: A front end is not available; certain operations require a front end.

Is there any work-around, or should I try a different approach?

  • 2
    $\begingroup$ You're indeed using a lot of functions that require the FrontEnd. Not sure why you think you could run that without FrontEnd. If you want this kind of interactivity why don't you simply use a notebook? $\endgroup$ May 17 '14 at 19:35

You can solve the issue by wrapping your code with UsingFrontEnd[].

  • $\begingroup$ I have both the script and the file in my home directory. If I run "./myScript data.csv" in terminal, I get this error "MathLink`Synchronized::noshare: -- Message text not found -- " $\endgroup$
    – mlainz
    May 18 '14 at 18:06
  • $\begingroup$ Sry, but it seems a different platform specific problem. When you run UsingFrontEnd[NotebookPut[Notebook[{Cell[Text["Test"]]}]]] in your script without the UsingFrontEnd you get the FrontEndObject error. You don't get any errors with. I do not know about the MathLink problem. $\endgroup$
    – Johu
    May 18 '14 at 19:37

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.