清除历史记录

清除历史记录

有没有办法可以设置 Safari 在启动时清除缓存和 cookie?也许我可以在启动应用程序时使用一个标志,或者甚至可以使用 bash 或 applescript 来删除硬盘上的文件,然后启动应用程序?

答案1

使用以下 AppleScript 代码并将其保存为应用程序AppleScript 编辑器或作为服务由单个运行 AppleScript行动自动机

tell application "Safari" to activate
tell application "System Events"
    tell application process "Safari"
        tell menu bar 1 to tell menu bar item "Safari" to tell menu 1 to tell menu item "Reset Safari…" to click
        tell window "Reset Safari" to tell button "Reset" to click
    end tell
end tell

这将激活 Safari,如果它未运行则启动它,然后打开并提交“重置 Safari...”菜单项。

答案2

希望这会有所帮助...我自己对 Applescript 还不熟悉,但我通过查看其他示例(例如上面的示例)将它们放在一起。

这些脚本被保存为应用程序。也许不是保存为应用程序,而是从查找器菜单创建这些服务...也许使用键盘快捷键也是一件好事。

第一个脚本(Safari ON)将以隐私浏览模式打开 Safari...然后重置 Safari...然后清除缓存。

第二个脚本(Safari OFF)将重置 Safari...清除缓存..然后关闭 Safari。

它们对我来说似乎都很好用,但就像我说的...我对此很陌生,我只做了两天。

如果您发现脚本有误...或者可以以某种方式改进它们,请随时向大家发布任何建议的更改。

=================

# Safari ON

# tell application "Safari"

activate
# end tell

# tell application "System Events"
tell process "Safari"
    tell menu bar 1
        tell menu bar item "Safari"
            tell menu "Safari"
                click menu item "Private Browsing"
            end tell
        end tell
    end tell
end tell
tell application process "Safari"
    tell menu bar 1 to tell menu bar item "Safari" to tell menu 1 to tell menu item "Reset Safari…" to click
    tell window "Reset Safari" to tell button "Reset" to click
end tell
# end tell
# tell application "System Events"
#   tell application process "Safari"
    tell menu bar 1 to tell menu bar item "Safari" to tell menu 1 to tell menu item "Empty Cache…" to click
end tell
# end tell

# tell application "System Events"
tell application process "Safari"
    click button "Empty" of front window
end tell
# end tell

执行相同的操作,但在关闭时:

# Safari OFF

# tell application "System Events"
tell application process "Safari"
    tell menu bar 1 to tell menu bar item "Safari" to tell menu 1 to tell menu item "Reset Safari…" to click
    tell window "Reset Safari" to tell button "Reset" to click
end tell
# end tell

# tell application "System Events"
tell application process "Safari"
    tell menu bar 1 to tell menu bar item "Safari" to tell menu 1 to tell menu item "Empty Cache…" to click
end tell
# end tell

# tell application "System Events"
tell application process "Safari"
    click button "Empty" of front window
end tell
# end tell
# tell application "Safari"
quit
# end tell

答案3

在隐私浏览模式下使用 Safari 不是更容易吗?这样一来,就不会保留任何信息

要使 Safari 启动时启用隐私浏览,请按照以下步骤操作

  1. 首先,启动通用访问系统首选项并启用启用辅助设备访问选项。

  2. 启动脚本编辑器(在应用程序文件夹内的 AppleScript 文件夹中)并输入以下脚本:

    tell application "Safari"
    
        activate
    end tell
    
    tell application "System Events"
        tell process "Safari"
        tell menu bar 1
        tell menu bar item "Safari"
        tell menu "Safari"
        click menu item "Private Browsing"
        end tell
        end tell
        end tell
        end tell
    end tell
    
  3. 将脚本保存为应用程序,然后使用该应用程序启动 Safari。执行此操作后,Safari 将启动并启用隐私浏览。

参考 :http://www.macworld.com/article/139714/2009/03/enableprivatebrowsing.html

答案4

清除历史记录

这是我为 Safari 编写的清除历史记录脚本版本。我已将其设置为德语版本,但可以轻松进行修改。

特征:

完全自动删除历史记录菜单和热门站点下的历史记录(可以通过删除not下面 if 语句中的来切换)。

tell application "Safari" to activate
tell application "System Events"
    tell process "Safari"
        tell menu bar item 6 of menu bar 1
            get name of menu items of menu 1
            click menu item "Verlauf löschen …" of menu 1
        end tell
        -- Window 1 immediately becomes the ARE YOU SURE pop up if history is not empty
        --return UI elements of window 1
        if role description of window 1 is "Dialog" then -- Ensures that the dialog pops up
            -- THE FOLLOWING ENSURES TOP SITES IS CHECKED
            set theCheckbox to checkbox 1 of window 1
            tell theCheckbox
                if not (its value as boolean) then click theCheckbox
            end tell
            click button "Löschen" of window 1
        end if
        display dialog "Safari history been cleaned." with title "Safari Cleaner Script" with icon caution
    end tell
end tell

--quit application "Safari"

相关内容