Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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} = 
  DialogInput[
   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?

share|improve this question
2  
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? –  Sjoerd C. de Vries May 17 at 19:35

1 Answer 1

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

share|improve this answer
    
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 -- " –  mlainz May 18 at 18:06
    
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. –  Johu May 18 at 19:37

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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