Using AppleScript or Automator to create custom data entry

I haven't read any posts about this exact situation, so I'm hoping someone out there can help me with this. Each day when I wake up there's certain bits of data I enter into an Excel spreadsheet. For example, I have a file that tracks my weight each day over many years. It's kind of a pain to have to manually open the file, enter the date and number, and extend the data range for the graph. What I'd love to set up is for Mac, upon awakening from sleep, to open a dialogue box that asks something like "What is your weight this morning?" and a data field for me to enter it in. Then when I click Save it will instantly migrate the current day's date and the data I just entered into the Excel file. Then I want it to refresh the graph with the new data. All without me having to open Excel. Can this be done via AppleScript or another utility? And on a related note, can the graph be turned into a dashboard widget? Many thanks!!!

iMac, Mac OS X (10.6.1), 27-inch, 3.06GHz

Posted on Oct 30, 2009 10:05 PM

Reply
6 replies

Oct 31, 2009 9:55 AM in response to SasquatchSF

Your major issue here is going to be your use of Excel.

For one, you cannot update the spreadsheet or the graph without opening Excel, so the request '... without me having to open Excel' isn't going to fly (unless you consider AppleScript opening Excel acceptable.

The second issue is finding the next row in the spreadsheet, extending the column and updating the graph reference. None of that is trivial thanks to Excel's AppleScript 'implementation'.

Although it's a lot more work, I'd take a slightly different route and get out of Excel altogether. Put the data in a database rather than a spreadsheet (this is data, after all), then you can use any number of database integration systems to update the data, extract the data, and draw your graphs.

AppleScript has the ability to write to SQLite databases thanks to the Database Events suite. MacTech has a great article about using Database Events which could be a good starting point.
A step up would be MySQL which then opens up all kinds of other possibilities such as a web-based interface (both for updates and graphing).

That may not be the answer you were hoping for, though. 🙂

Oct 31, 2009 12:11 PM in response to Camelot

Thanks, this is great info! I guess this little project will wind up being more complicated than I had hoped, since I've never used Database Events or MySQL, but I guess this is a good excuse to start learning about these kinds of programs.

If I add my existing data to MySQL, can you recommend a free/low-cost interface to handle the updates and graphing? It doesn't need to be anything fancy.

Oct 31, 2009 3:41 PM in response to Camelot

I'll make an interim suggestion. since this is not something that requires the power of a full relational database, you might just want to convert your current data to a simple tab-delimited text file. Applescript can write to a text file with very little effort, and a tab delimited text file can be easily opened in excel for processing. example:
display dialog "What is your weight this morning, kind sir or madam?" default answer "10000"
set theWeight to text returned of the result as integer
set theDate to date string of (current date)
set theText to theDate & tab & theWeight & return
set fp to open for access alias "path:to:datafile.txt" with write permission
write theText to fp starting at (get eof fp) + 1
close access fp

this gets your the current date, your current weight, and then writes them to the end of the file you specify. Of course, you'll have to convert your current excel data sheet to tab delimited format (easily handled in the 'Save As...' dialog), and adjust the script to reflect the structure you have in the document now...

Oct 31, 2009 4:04 PM in response to SasquatchSF

If I add my existing data to MySQL, can you recommend a free/low-cost interface to handle the updates and graphing? It doesn't need to be anything fancy.


Sure, PHP and Google 🙂

PHP can be used to create a web-based front end to your data - both for inputting new data and extracting the data.

You can also use the Google Visualization API set to visualize your data - present it in graphs of varying styles. IMHO this is actually easier than trying to implement graphing within PHP - not that it's a trivial task in itself, but once you have the data a PHP script can output it in the right format for the visualization API.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Using AppleScript or Automator to create custom data entry

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.