Erase Safari cookies from Terminal

荒凉一梦 提交于 2019-12-23 10:53:21

问题


I am making an application that involves controlling Safari from Applescript. Is there a way in the Terminal (preferred) or Applescript to erase Safari's cookies. Basically I want to the "Reset Safari" item from the menu using the Terminal. Is there a method that can do this?


回答1:


You could simply delete the Cookies.plist file:

rm ~/Library/Cookies/Cookies.plist

Or take a look at this: List & delete Safari cookies




回答2:


Reset Safari does more than just erasing the cookies:

Basically I want to the "Reset Safari" item from the menu using the Terminal.

If you would want to completely reset Safari from the terminal, you would use (depending on the Safari version the commands may vary):

rm ~/Library/Safari/History.plist

rm ~/Library/Safari/Downloads.plist

rm ~/Library/Safari/HistoryIndex.sk

rm ~/Library/Safari/LastSession.plist

rm ~/Library/Safari/TopSites.plist

rm -rf ~/Library/Caches/com.apple.safari

And (a little unsure about the last one):

rm ~/Library/Safari/SearchProviders.plist.signed



回答3:


You can reset Safari using the following AppleScript (GUI scripting must be enabled):

tell application "System Events"
tell process "Safari"
    set frontmost to true
    click menu item "Reset Safari…" of menu 1 of menu bar item "Safari" of menu bar 1
    --delay 1 --may be uncommented if needed
    click button "Reset" of window 1
end tell
end tell


来源:https://stackoverflow.com/questions/899851/erase-safari-cookies-from-terminal

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!