Local Applescript Database

Hello all,

 I am trying to create a databse using applescript and then give it a front end, so it will consist of a front end with a simple table, a button to add the text, which comes from a plain text field.  Now, as far as the back-end, I believe all it needs is to on the pushing of the button, grabbing the text string from the text field and then printing it into the table?  Does this sound correct and can anyone lead me in the right direction on where to start?  By the way, I am a newbie at applescripting so any help is very appreciated.  Thanks!


What you propose to do would certainly work, but it won’t give you a database. The next time you start up your application, you’ll have lost all your data. What you need is to write your data to an actual database. The simplest way to do this, at first, would be to write your stuff to the user defaults, like so:

make new default entry at end of default entries of user defaults with properties {name:"Fruit", contents:"Apple"}

This is fine for small amounts of data that other users don’t need to access (the user defaults are different for each user). Alternatively you could write your data to a text file, using one line (paragraph) for each entry. Otherwise, you’ll need to use a proper database like SQLite, MySQL or even Filemaker. Filemaker is scriptable but I had the hardest time making it behave. Nevertheless, people do use it.
MySQL (you’d have to install that first, see macports.org) and SQLite (is already on your system). You can access both from the command line which means you would have to familiarize yourself with the “do shell script” command. If you want to go that route, I have scripts that will get your requests from the database and return them as list-based recordsets. Anyhow, you’ll need to learn some SQL as well to make meaningful queries.
And finally, there is Core Data, which allows you to make a marvelous data model and bind it to your interface. To see what it is all about, check out http://developer.apple.com/cocoa/coredatatutorial/index.html
Using a database in your applescript applications takes a bit of work, but once you start, you’ll never look back.

Thank you, CoreData ireally cool and now my favoirte new tool, watch out for some new applications coming to you in CoreData!


Looking forward to them. You’ll also want to look at the tutorial on cocoaDev http://www.cocoadevcentral.com/articles/000085.php
. For one, shows you how to change your persistent store from an xml file (the default) to a sqlite database (a bit slower but a lot more capacity). Good luck.

I have to amend my recommendation for changing the persistent store from the default xml file to a sqlite database. These past days I’ve found that once you do that, changing the data model becomes a bit of a chore. Basically what happens is that when you add an attribute or entity in the datamodel, Xcode 2.4 fails to change the SQLite database as well. For further details, see my post on the CocoaDev mailinglist:
To me it looks like a problem that should not be too hard to fix, but in the meantime, if you’re still experimenting with your data model, you’ll probably be happier if you stick to the default xml file.