Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I programmatically delete cookies in Safari 8.0 on OS X 10.10 (Yosemite)

In Safari 8.0 (10600.1.25.1) on OS X 10.10.1 (Yosemite), I visit some sites like google.com, apple.com, facebook.com and can then see the cookies when I click "Safari" -> "Preferences..." -> "Privacy" -> "Details..."

I then quit Safari completely (actually quit, not just close the window), and delete the following things using the following.

rm -r ~/Library/Caches/com.apple.Safari/ rm -r ~/Library/Cookies rm -r ~/Library/Safari

When I restart Safari, the cookies are still there and I'm still logged in to a website that stored a cookie after login.

Which files do I need to delete or what do I have to do to get Safari to actually delete the cookies?

I need to be able to move/rename the files/directories and then move them back at a later time. Cocoa Cookies can delete the cookies (http://ditchnet.org/cocoacookies/) and when I use fswatch there are no interesting files that change.

like image 594
AaronJ Avatar asked Dec 02 '14 16:12

AaronJ


People also ask

How do I automatically delete cookies in Safari?

In the Safari app on your Mac, choose Safari > Preferences, click Privacy, then do any of the following: Prevent trackers from using cookies and website data to track you: Select “Prevent cross-site tracking.” Cookies and website data are deleted unless you visit and interact with the trackers' websites.

How do I clear cookies on my Mac Yosemite?

Pull down “Safari” menu and click “Preferences” Choose the “Privacy” tab. Click the “Remove All Website Data” button alongside “Cookies and other website data” and confirm at the popup to delete all cookies.

Why can't I remove cookies from my Mac?

In the Preferences menu, click on the Privacy tab. To prevent third-party trackers from using cookies to track you, click the Prevent cross-site tracking box. To clear cookies, click Manage Website Data. In pop-up window, click Remove All.


2 Answers

I think Apple Script is the road to take here, give a look at the linked blog entry here. Below I copied the google script example.

 1  set deCookie to {"nytimes.com", "go.com", "cnn.com"}
 2  
 3  tell application "System Events"
 4    tell process "Safari"
 5      keystroke "," using command down
 6      delay 1
 7      tell window 1
 8        click button "Privacy" of tool bar 1
 9        delay 3
10        repeat with d in deCookie
11          click button "Details…" of group 1 of group 1
12          try
13            keystroke d
14            delay 1
15            select row 1 of table 1 of scroll area 1 of sheet 1
16            click button "Remove" of sheet 1
17          end try
18          click button "Done" of sheet 1
19        end repeat
20      end tell
21      keystroke "w" using command down
22    end tell
23  end tell
like image 116
Fabian Avatar answered Sep 28 '22 16:09

Fabian


A bit late I know, but I made RemoveCookie, a command line utility that deletes Safari cookies. Pretty straightforward, it uses the NSHTTPCookieStorage API, which anyone looking to manage Safari cookies may find useful.

like image 45
robmathers Avatar answered Sep 28 '22 14:09

robmathers