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?