PDA

View Full Version : Saving with JavaScript (widgets)




mrzeve
Feb 9, 2007, 01:13 AM
Hey guys.

I was wondering if anyone had any experience with saving information through javascript.

For example, I'm developing a widget, and I want to add the ability for the user to be able to save the text of the story they are reading.

It doesn't have to automatically save, I'm fine with a dialog box can pop up asking them where/if they would like to save the file.

Any help at all would be appreciated. Just need to be steered in the right direction.

Thanks a bunch.



robbieduncan
Feb 9, 2007, 04:14 AM
The general JavaScript environment (in a web browser) explicitly can't write to local files at all. You might have some luck as you are in Dashboard but I suspect it'd be better to write the save component in Cocoa and link that to your widget (which is easily possible).

mrzeve
Feb 9, 2007, 12:24 PM
The general JavaScript environment (in a web browser) explicitly can't write to local files at all. You might have some luck as you are in Dashboard but I suspect it'd be better to write the save component in Cocoa and link that to your widget (which is easily possible).

Thanks a bunch for that. I've seen many widgets that have the ability to save and I guess thats the way they do it. Plugins.

Now I need to learn Cocoa and figure out how to implement it into the widget :rolleyes:

maximile
Feb 9, 2007, 04:07 PM
There's nothing to stop you from using

widget.setPreferenceForKey(preference, key)
widget.preferenceForKey(key)

to store strings. AFAIK.

robbieduncan
Feb 10, 2007, 04:00 AM
There's nothing to stop you from using

widget.setPreferenceForKey(preference, key)
widget.preferenceForKey(key)

to store strings. AFAIK.

That stores the data in the user preferences, a binary or text xml file in ~/Library/Preferences. This should not be used to store anything other than user preferences...

mrzeve
Feb 10, 2007, 11:55 AM
So I realized what I wanted could be done a lot easier with AppleScript than in JavaScript.

So I successfully created a .scrpt file and then learnt that I needed to use Xcode to create a bundle for the widget.

So I simply created a Carbon (or was it Cocoa?) bundle project and added the Applescript to it. Then I changed the wrapper extension from .bundle to .widgetplugin.

I then added it to the widget (note; I'm using Dashcode) and thought I could call it successfully, but I'm kind of confused on the calling process....anyone know how its supposed to be done? My AppleScript has several functions in it, how do I call them, and also, am I calling by the scripts name it self or do I simply call the function name straight up from the widget?

Any help would be great