Re: Cookies and XMLLib.osax
Re: Cookies and XMLLib.osax
- Subject: Re: Cookies and XMLLib.osax
- From: "Gary (Lists)" <email@hidden>
- Date: Sat, 17 Sep 2005 12:31:44 -0400
"Michael Ghilissen" wrote:
> I am trying the new XMLLib.osax 2.7 from Satimage to clean up my Safari
> Cookies.plist. I want to eliminate unwanted cookies and leave out a list of
> approved cookies. So far I can read and select the approved cookies, but I
> have some troubles to write a new plist, complete with the header. Can someone
> give me a help?
PlistNew makes a new plist _in memory_.
PlistSave saves it to disk.
This short sample will create a plist and then write it to disk,
(in the simplest form of the commands, which can take more parameters, of
course):
I'll use an AS record to keep it simple.
--
set pData to {str:"Hello, world.",id:1}
set aPlistInMemory to PlistNew pData -- fully structured XML plist [*]
set outputPath to "" & (path to "desk") & "michael.plist"
PlistSave aPlistInMemory to outputPath -- it's now on disk
--
[*] That's what you meant by "complete with header", right?
In general, keep in mind that you can (I think _should_) read the plist from
file to memory (a variable) and then work with that data until you are ready
to write it back to file. Make sense?
> set the_folder to ("Macintosh HD:Users:michael:Library:Cookies:") as text
> set the_file to (the_folder & "Cookies.plist") as alias set the_plist to
> PlistOpen the_file
-- better (IMO)...
set cookiePlist to PlistOpen the_file -- now you work with 'cookiePlist'
> --enter a list of acceptable cookies by <Domain> set the_okookies to
> {".apple.com", "mail.google.com", ".msn.com", ".yahoo.com"}
>
> try
> repeat with i from 1 to 5 -- for a full loop, change to: PlistCount the_plist
> set _node to PlistChild the_plist index i
> set TheResult to PlistGet (PlistChild _node key "Domain")
Right there ^ you set a variable, TheResult, yet...
> if (PlistGet (PlistChild _node key "Domain")) is in the_okcookies then ¬
...here ^ you don't use it. You could be more efficient by typing...
if TheResult is in the_okcookies then ¬
> -- here I need help to write a new plist
> -- with the selected information contained in (PlistGet _node)
Strictly answering, without exactly following your process, if your complete
plist data will be returned by (PlistGet _node), and that's what you want to
use to make a new on-disk plist with, then:
-- if you want it also in a variable then...
set michaelsNewPlist to PlistNew (PlistGet _node)
PlistSave michaelsNewPlist in outputPath
-- else if you don't care and you don't get an error then ...
PlistSave PlistNew (PlistGet _node) in outputPath
I really don't use that last form and didn't even try it, so... <shrug>.
> end repeat
> on error theErr
> display dialog theErr
> end try
> PlistClose the_plist
If working samples help you, then you can get the source code for a script
that also uses the Satimage XMLLib osax, with Safari's bookmark file. It
does all the same kinds of tasks: reads the plist from disk, does some
manipulating, writes the plist back to file.
The working script, a read me and the source code are all here:
<http://orgdork.org/safari/AddSafariBookmark.html>
--
Gary
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden