Never been to CodeSnippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)

List & delete Safari cookies (See related posts)

# for PlistBuddy see: http://codesnippets.joyent.com/posts/show/1484

# list Safari cookies
function lsc() {
   /usr/libexec/PlistBuddy -c print ~/Library/Cookies/Cookies.plist | \
      /usr/bin/awk '/^[[:space:]]+Domain = /{sub( /^[[:space:]]+Domain =[[:space:]]+/,""); print}' | \
      /usr/bin/sort -u | /usr/bin/nl
      #/usr/bin/awk '!x[$0]++' | /usr/bin/sed -n '1!G;h;$p' | /usr/bin/nl
   return 0
}

lsc


# delete Safari cookies except ...
# ... for those domains specified by an egrep regex

/usr/libexec/PlistBuddy -c Print ~/Library/Cookies/Cookies.plist
/usr/libexec/PlistBuddy -c 'Print :0' ~/Library/Cookies/Cookies.plist
/usr/libexec/PlistBuddy -c 'Print :1' ~/Library/Cookies/Cookies.plist


function dsce() {

   declare array_indices cookiesplistfile index regex

   regex="${1:-$'\777'}"   # delete all cookies if there is no argument $1; for \777 see man ruby
   cookiesplistfile="${HOME}/Library/Cookies/Cookies.plist"

   array_indices="$(/usr/libexec/PlistBuddy -c print "${cookiesplistfile}" | /usr/bin/awk '/Domain = /{x++;print x-1,$0}' | \
       /usr/bin/egrep -iv "${regex}" | /usr/bin/awk '{print $1}' | /usr/bin/sort -rn)"

:<<-'COMMENT'
   # test
   for index in ${array_indices}; do 
      echo $index; 
      #/usr/libexec/PlistBuddy -c "Print :'${index}'" "${cookiesplistfile}" 
      /usr/libexec/PlistBuddy -c "Print :'${index}':Domain" "${cookiesplistfile}" 
   done
COMMENT

   for index in ${array_indices}; do 
      /usr/libexec/PlistBuddy -c "Delete :'${index}'" "${cookiesplistfile}" 
   done

   /usr/libexec/PlistBuddy -c save "${cookiesplistfile}" &>/dev/null

   return 0

}


lsc

dsce 'xxx.com|xxx.org'

lsc

Comments on this post

uggs12 posts on Mar 15, 2010 at 04:27
I received my cheapest ghd iv mini styler today, very impressed. They are like sort of a massive slipper, soft, easy to wear and light.My ghd iv styler uk arrived today, I'm very pleased with them. So silky smooth and soft I can't believe it. I researched the whole ghd iv mini styler uk thing last year but decided not to order because I really couldn't afford a pair. This year I read about Whooga's in a fashion forum and decided to give them a try. I ordered a size too small initially and had to return them for a 6 which was a bit annoying but eventually worth the wait, I'm a 5.5 in most shoes but boots sometimes vary between 5.5 and 6. I probably should have measured my foot, anyway I'm very pleased. cheap ghd iv mini styler ...

You need to create an account or log in to post comments to this site.