Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > In need of help with AppleScript Studio saving settings.

In need of help with AppleScript Studio saving settings.
Thread Tools
Fresh-Faced Recruit
Join Date: Feb 2001
Status: Offline
Reply With Quote
Jul 24, 2002, 05:52 PM
 
Hello, I am making a front-end for wget with applescript studio. I am not really near done, but I have ran into a problem which I cannot figure out how to solve. I have a preferences window with some preferences. For some reason, when I set some of them and relaunch the app, they are not saved. This is strange, as I followed the method for doing this used in the sample-app 'ArchiveMaker'. Anyone who thinks he or she can help, grab the source here:

<a href="http://homepage.mac.com/mingtsai/wgetsource.tgz" target="_blank">http://homepage.mac.com/mingtsai/wgetsource.tgz</a>

thanks
     
Mac Elite
Join Date: Oct 2000
Status: Offline
Reply With Quote
Jul 24, 2002, 06:30 PM
 
</font><blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">quote:</font><hr /><font size="1" face="Geneva, Verdana, Arial, sans-serif">Originally posted by mingtsai:
<strong>Hello, I am making a front-end for wget with applescript studio. I am not really near done, but I have ran into a problem which I cannot figure out how to solve. I have a preferences window with some preferences. For some reason, when I set some of them and relaunch the app, they are not saved. This is strange, as I followed the method for doing this used in the sample-app 'ArchiveMaker'. Anyone who thinks he or she can help, grab the source here:

<a href="http://homepage.mac.com/mingtsai/wgetsource.tgz" target="_blank">http://homepage.mac.com/mingtsai/wgetsource.tgz</a>

thanks</strong></font><hr /></blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">Are you simply using properties and wanting them to stick? Because they purposely don't work anymore.. Read the docs for the user defaults class.
     
Fresh-Faced Recruit
Join Date: Feb 2001
Status: Offline
Reply With Quote
Jul 24, 2002, 06:40 PM
 
I had not heard about properties not working anymore. It seems that they still work for this purpose, as in apple's archivemaker example applicaiton, properties are used.
     
Mac Elite
Join Date: Oct 2000
Status: Offline
Reply With Quote
Jul 25, 2002, 12:59 AM
 
</font><blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">quote:</font><hr /><font size="1" face="Geneva, Verdana, Arial, sans-serif">Originally posted by mingtsai:
<strong>I had not heard about properties not working anymore. It seems that they still work for this purpose, as in apple's archivemaker example applicaiton, properties are used.</strong></font><hr /></blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">Well of course they work for normal global type use. But they purposely aren't maintained after you terminate the app as in a script. It is your job to write these out to a plist via the user defaults class. There was a huge discussion about this in AppleScript Studio's initial release and it pops up as a frequent question, still.
     
Fresh-Faced Recruit
Join Date: Feb 2001
Status: Offline
Reply With Quote
Jul 25, 2002, 03:24 PM
 
</font><blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">quote:</font><hr /><font size="1" face="Geneva, Verdana, Arial, sans-serif">Originally posted by Synotic:
<strong> </font><blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">quote:</font><hr /><font size="1" face="Geneva, Verdana, Arial, sans-serif">Originally posted by mingtsai:
<strong>I had not heard about properties not working anymore. It seems that they still work for this purpose, as in apple's archivemaker example applicaiton, properties are used.</strong></font><hr /></blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">Well of course they work for normal global type use. But they purposely aren't maintained after you terminate the app as in a script. It is your job to write these out to a plist via the user defaults class. There was a huge discussion about this in AppleScript Studio's initial release and it pops up as a frequent question, still.</strong></font><hr /></blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">I did, and that is why I am having trouble. I cannot seem to pinpoint what is wrong even though I am almost sure that this is the correct code:

on registerSettings()
tell user defaults
make new default entry at end of default entries with properties {name:"noHostLookup", contents:noHostLookup}
make new default entry at end of default entries with properties {name:"noParent", contents:noParent}
make new default entry at end of default entries with properties {name:"relativeWget", contents:relativeWget}
make new default entry at end of default entries with properties {name:"spanHosts", contents:spanHosts}

register
end tell
end registerSettings

Similar code for readSettings (save to boolean) and writeSettings (update settings).

Is the problem here, or does it deal with IB? This is only my second time using IB, though I know a bit of applescript.
     
Mac Elite
Join Date: Oct 2000
Status: Offline
Reply With Quote
Jul 25, 2002, 08:37 PM
 
</font><blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">quote:</font><hr /><font size="1" face="Geneva, Verdana, Arial, sans-serif">Originally posted by mingtsai:
<strong> </font><blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">quote:</font><hr /><font size="1" face="Geneva, Verdana, Arial, sans-serif">Originally posted by Synotic:
<strong> </font><blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">quote:</font><hr /><font size="1" face="Geneva, Verdana, Arial, sans-serif">Originally posted by mingtsai:
<strong>I had not heard about properties not working anymore. It seems that they still work for this purpose, as in apple's archivemaker example applicaiton, properties are used.</strong></font><hr /></blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">Well of course they work for normal global type use. But they purposely aren't maintained after you terminate the app as in a script. It is your job to write these out to a plist via the user defaults class. There was a huge discussion about this in AppleScript Studio's initial release and it pops up as a frequent question, still.</strong></font><hr /></blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">I did, and that is why I am having trouble. I cannot seem to pinpoint what is wrong even though I am almost sure that this is the correct code:

on registerSettings()
tell user defaults
make new default entry at end of default entries with properties {name:"noHostLookup", contents:noHostLookup}
make new default entry at end of default entries with properties {name:"noParent", contents:noParent}
make new default entry at end of default entries with properties {name:"relativeWget", contents:relativeWget}
make new default entry at end of default entries with properties {name:"spanHosts", contents:spanHosts}

register
end tell
end registerSettings

Similar code for readSettings (save to boolean) and writeSettings (update settings).

Is the problem here, or does it deal with IB? This is only my second time using IB, though I know a bit of applescript.</strong></font><hr /></blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">You're aren't saving any arrays (lists) are you? I'd need to see the other code that you use for writing/reading.
     
Fresh-Faced Recruit
Join Date: Feb 2001
Status: Offline
Reply With Quote
Jul 25, 2002, 10:34 PM
 
</font><blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">quote:</font><hr /><font size="1" face="Geneva, Verdana, Arial, sans-serif">You're aren't saving any arrays (lists) are you? I'd need to see the other code that you use for writing/reading.[/QB]</font><hr /></blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">on getSettingsFromUI()
tell window "preferences"
set noHostLookup to (state of button "--no-host-lookup (-nh)") as boolean
set noParent to (state of button "--no-parent (-np)") as boolean
set relativeWget to (state of button "--relative (-L)") as boolean
set spanHosts to (state of button "--span-hosts (-H)") as boolean
end tell
end getSettingsFromUI

-------

on setSettingsInUI()
tell window "preferences"
set state of button "--no-host-lookup (-nh)" to noHostLookup
set state of button "--no-parent (-np)" to noParent
set state of button "--relative (-L)" to relativeWget
set state of button "--span-hosts (-H)" to spanHosts
end tell
end setSettingsInUI

-------

on registerSettings()
tell user defaults
make new default entry at end of default entries with properties {name:"noHostLookup", contents:noHostLookup}
make new default entry at end of default entries with properties {name:"noParent", contents:noParent}
make new default entry at end of default entries with properties {name:"relativeWget", contents:relativeWget}
make new default entry at end of default entries with properties {name:"spanHosts", contents:spanHosts}

register
end tell
end registerSettings

-------

on readSettings()
tell user defaults
set noHostLookup to contents of default entry "noHostLookup" as boolean
set noParent to contents of default entry "noParent" as boolean
set relativeWget to contents of default entry "relativeWget" as boolean
set spanHosts to contents of default entry "spanHosts" as boolean
end tell
end readSettings

-------

on writeSettings()
tell user defaults
set contents of default entry "noHostLookup" to noHostLookup
set contents of default entry "noParent" to noParent
set contents of default entry "relativeWget" to relativeWget
set contents of default entry "spanHosts" to spanHosts
end tell
end writeSettings
     
Mac Elite
Join Date: Oct 2000
Status: Offline
Reply With Quote
Jul 26, 2002, 12:24 AM
 
Try saving as a string rather than a boolean.
     
Fresh-Faced Recruit
Join Date: Feb 2001
Status: Offline
Reply With Quote
Jul 26, 2002, 11:44 AM
 
</font><blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">quote:</font><hr /><font size="1" face="Geneva, Verdana, Arial, sans-serif">Originally posted by Synotic:
<strong>Try saving as a string rather than a boolean.</strong></font><hr /></blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">Still a no-go. I am beginning to think I have not tagged something in Interface Builder correctly. Anyone here good at working with Interface Builder?
     
Mac Elite
Join Date: Oct 2000
Status: Offline
Reply With Quote
Jul 26, 2002, 11:53 AM
 
</font><blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">quote:</font><hr /><font size="1" face="Geneva, Verdana, Arial, sans-serif">Originally posted by mingtsai:
<strong> </font><blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">quote:</font><hr /><font size="1" face="Geneva, Verdana, Arial, sans-serif">Originally posted by Synotic:
<strong>Try saving as a string rather than a boolean.</strong></font><hr /></blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">Still a no-go. I am beginning to think I have not tagged something in Interface Builder correctly. Anyone here good at working with Interface Builder?</strong></font><hr /></blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">"Good" with Interface Builder? Unlike coding there isn't really any skill attributed with it. Have you actually tried setting the state using a boolean before? Last time I checked I think it was done with an integer.

set state of button "cbox" to 1

or 0 to turn it off. You can just directly save as an integer and spare the coercion and it'll be read back normally. Also, your script compiles.. no errors? What's with the "register" line? in the registerSettings handler?

Did you check your ~/Library/Preferences to see if it was actually creating the file? What was being saved? Etc...
     
Fresh-Faced Recruit
Join Date: Feb 2001
Status: Offline
Reply With Quote
Jul 26, 2002, 01:15 PM
 
</font><blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">quote:</font><hr /><font size="1" face="Geneva, Verdana, Arial, sans-serif">Originally posted by Synotic:
<strong> </font><blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">quote:</font><hr /><font size="1" face="Geneva, Verdana, Arial, sans-serif">Originally posted by mingtsai:
<strong> </font><blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">quote:</font><hr /><font size="1" face="Geneva, Verdana, Arial, sans-serif">Originally posted by Synotic:
<strong>Try saving as a string rather than a boolean.</strong></font><hr /></blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">Still a no-go. I am beginning to think I have not tagged something in Interface Builder correctly. Anyone here good at working with Interface Builder?</strong></font><hr /></blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">"Good" with Interface Builder? Unlike coding there isn't really any skill attributed with it. Have you actually tried setting the state using a boolean before? Last time I checked I think it was done with an integer.

set state of button "cbox" to 1

or 0 to turn it off. You can just directly save as an integer and spare the coercion and it'll be read back normally. Also, your script compiles.. no errors? What's with the "register" line? in the registerSettings handler?

Did you check your ~/Library/Preferences to see if it was actually creating the file? What was being saved? Etc...</strong></font><hr /></blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">Ok, I tested it. The settings do need to be saved as boolean. Otherwise, you get an error. When set to boolean, the options take effect. This means that the problem, I think, must be in the saving or reading of the settings. I put the register at the end of that line because in the apple documentation/examples, it uses it. It does not seem to matter if I have it or not though. Also, a 'wget.plist' is created, but all that is inside is a 'BinaryPath' string and a NSWIndow Frame preferences string. I am not sure if this is all that is supposed to be there. Somehow, now, however, it seems that the wget.plist is not being modified when I fool with settings in the application. Strange. Could the problem be with the event handlers which occur at the launch and quit of the application?

on will finish launching theObject
registerSettings()
readSettings()
end will finish launching

---

on will quit theObject
getSettingsFromUI()
writeSettings()
end will quit
     
Fresh-Faced Recruit
Join Date: Feb 2001
Status: Offline
Reply With Quote
Jul 28, 2002, 02:49 PM
 
Anyone?
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 12:35 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2