macos 从终端清除 Safari cookie

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/899851/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 06:10:40  来源:igfitidea点击:

Erase Safari cookies from Terminal

macossafariterminalapplescript

提问by hekevintran

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?

我正在制作一个涉及从 Applescript 控制 Safari 的应用程序。终端(首选)或 Applescript 中有没有办法清除 Safari 的 cookie。基本上我想使用终端从菜单中“重置 Safari”项目。有没有一种方法可以做到这一点?

采纳答案by Gumbo

You could simply delete the Cookies.plistfile:

您可以简单地删除该Cookies.plist文件:

rm ~/Library/Cookies/Cookies.plist

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

或者看看这个:List & delete Safari cookies

回答by alexyorke

Reset Safari does more than just erasing the cookies:

重置 Safari 不仅仅是擦除 cookie:

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

基本上我想使用终端从菜单中“重置 Safari”项目。

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

如果您想从终端完全重置 Safari,您可以使用(取决于 Safari 版本,命令可能会有所不同):

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

回答by Gumbo

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

您可以使用以下 AppleScript 重置 Safari(必须启用 GUI 脚本):

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