Ken
Ken

Reputation: 118

How to script Excel or Numbers on a mac, and launch from bash?

I want to write a bash script for a mac which takes a text file containing a table of numbers (can be .csv), converts the numbers to a chart, saves the chart (any file format that I can display on my web page), and exits. It must do this unattended. No user interaction.

I know bash, perl, and a little AppleScript, and I can learn VBA or whatever else. I am about to plunk down money for the new Excel 2011 for Mac. I think I want Excel rather than Numbers'09, but I am not at all sure, and I think VBA or AppleScript will allow me to automate most of the work.

Is AppleScript + Excel a good choice? If so, then I'm home free. Applescript programs can be launched from bash via osascript command.

But maybe VBA is better? But how can I launch a Excel VBA script from bash on a mac?

Summary of questions: (1) AppleScript or VBA or something else? (2) Excel or Numbers? (3) How to launch Excel VBA script from bash?

Thanks in advance, Ken

Upvotes: 1

Views: 3085

Answers (6)

Igbanam
Igbanam

Reputation: 6082

I would recommend using Numbers and AppleScript if you are on OS X—these are well integrated. Also, you could use Automator to make your life even simpler.

Upvotes: 0

Orbling
Orbling

Reputation: 20612

You might like to take a look at Google Chart Tools.

It is exceptionally useful for including charts and graphs within web pages.

You just create a URL containing the data as a src for an image, then tada, it appears.

Have a play.

For instance, a few parameters:

chd=t:10,20,30
chco=FF0000|00FF00|0000FF
chs=320x240
cht=p3
chdl=Red|Green|Blue

Makes a URL: https://chart.googleapis.com/chart?chd=t:10,20,30&chco=FF0000|00FF00|0000FF&chs=320x240&cht=p3&chdl=Red|Green|Blue

Which forms a chart:

Example Pie Chart

Upvotes: 0

Asmus
Asmus

Reputation: 5257

You should definitively consider using gnuplot (free), which can easily create graphics and even HTML5 canvas elements from different input file formats via the command line.

Upvotes: 1

proFromDover
proFromDover

Reputation: 461

Don't forget to try OpenOffice (and derivatives). It's been a while since I last worked with it, but they have a macro language and some VBA support (don't know how good it is now, I'm sure it's progressed) - so it could likely generate your graphs for you.

Alternatively, this sounds like something Gnuplot could very easily do. See this article where they start with the raw data in a text file, and create a PNG file for use in a web page: http://www.ibm.com/developerworks/aix/library/au-gnuplot/index.html

Just thought you should know about other options than Excel and Numbers...

Upvotes: 2

Clark
Clark

Reputation: 818

iWork 09 does support Applescript. Pages is pretty good with its support. Numbers far less so. I think most expect more expansive Applescript support with the new version as Numbers only has partial support. So for what the original question asks you really need to use Excel.

If you are going to script I'd look seriously at Python or Ruby combined with Appscript rather than Applescript or VBA. Applescript is a bear of a language to write in and using one of the other languages gives you all the libraries of that language. That allows quite a bit more powerful code to be written.

If you are just writing for Office and don't need much other functionality then I'd probably stick with VBA.

Upvotes: 0

Philip Regan
Philip Regan

Reputation: 5055

Microsoft removed VBA support from Office with v2008. iWork '08 has no Applescript support, and while I can't speak directly about v'09 given Apple's recent decline in scriptable applications I wouldn't count on it.

The sure, long-term bet here would be to use Excel with Applescript.

Upvotes: -1

Related Questions