• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Plist entry
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Plist entry


  • Subject: Re: Plist entry
  • From: Axel Luttgens <email@hidden>
  • Date: Sat, 19 Jan 2008 15:41:49 +0100

On 19/01/08 14:18, Michael Ghilissen wrote:

I want to create a cookies management script for Safari, which creates a new plist by:
1/ reading the original plist,
2/ selecting only those cookies, which are authorized, and
3/ writing an new plist .


The format of the plist must be Safari's.

Thanks for those explanations.

So, let's start with a newly created Cookies.plist, after having opened Apple's home page:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd";>
<plist version="1.0">
<array>
<dict>
<key>Created</key>
<real>222442409.37105501</real>
<key>Domain</key>
<string>.apple.com</string>
<key>Expires</key>
<date>2008-02-18T13:33:29Z</date>
<key>Name</key>
<string>s_nr</string>
<key>Path</key>
<string>/</string>
<key>Value</key>
<string>1200749609370</string>
</dict>
<dict>
<key>Created</key>
<real>222442409.85446599</real>
<key>Domain</key>
<string>.apple.com</string>
<key>Expires</key>
<date>2013-01-17T13:33:29Z</date>
<key>Name</key>
<string>s_vi</string>
<key>Path</key>
<string>/</string>
<key>Value</key>
<string>[CS]v1|4791FC290000379D-A2B0C0800000111[CE]</string>
</dict>
</array>
</plist>


This is thus an array of dicts.

Let's see how System Events interprets it:

tell application "System Events"
set PLValue to value of contents of property list file "~/Library/Cookies/Cookies.plist"
end tell


This returns a list of records (hence: array -> list, dict -> record); after some formatting, that list of records is:

{
   {
       |Path|:"/",
       |Expires|:date "lundi 18 février 2008 14:33:29",
       |Domain|:".apple.com",
       |Value|:"1200749609370",
       |Created|:2.22442409371055E+8,
       |Name|:"s_nr"
   },
   {
       |Path|:"/",
       |Expires|:date "jeudi 17 janvier 2013 14:33:29",
       |Domain|:".apple.com",
       |Value|:"[CS]v1|4791FC290000379D-A2B0C0800000111[CE]",
       |Created|:2.22442409854466E+8,
       |Name|:"s_vi"
   }
}

So, as Luther already has outlined, one needs to build the list with the records to be kept and save it back to a file.
For example, assuming you want to keep cookies related to "apple.com":


tell application "System Events"
set PL to contents of property list file "~/Library/Cookies/Cookies.plist"
set PLValue to value of PL
set NewPLValue to {}
repeat with R in PLValue
if |Domain| of R ends with "apple.com" then set end of NewPLValue to contents of R
end repeat
set NewPL to make new property list item with properties {value:NewPLValue}
make new property list file with properties {name:"~/Desktop/Cookies.plist", contents:NewPL}
end tell


Of course, there is sure more than one way to do it... ;-)
Axel
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden
  • Follow-Ups:
    • Re: Plist entry
      • From: Luther Fuller <email@hidden>
References: 
 >Plist entry (From: Michael Ghilissen <email@hidden>)
 >Re: Plist entry (From: Axel Luttgens <email@hidden>)
 >Re: Plist entry (From: Michael Ghilissen <email@hidden>)
 >Re: Plist entry (From: Axel Luttgens <email@hidden>)
 >Re: Plist entry (From: Michael Ghilissen <email@hidden>)

  • Prev by Date: Re: Editing Lists of LISTS
  • Next by Date: Re: Plist entry
  • Previous by thread: Re: Plist entry
  • Next by thread: Re: Plist entry
  • Index(es):
    • Date
    • Thread