Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

mrzeve

macrumors 6502a
Original poster
Jan 25, 2005
617
1
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

Moderator emeritus
Jul 24, 2002
25,611
893
Harrogate
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

macrumors 6502a
Original poster
Jan 25, 2005
617
1
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:
 

robbieduncan

Moderator emeritus
Jul 24, 2002
25,611
893
Harrogate
There's nothing to stop you from using

Code:
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

macrumors 6502a
Original poster
Jan 25, 2005
617
1
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
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.