返回

自动化达人看过来:AppleScript 批量删除Mac信息绝技

闲谈

准备工作

在开始之前,我们需要确保已经安装了 AppleScript。AppleScript 是 macOS 系统自带的工具,通常已经预装在电脑中。如果你的电脑中没有 AppleScript,可以从苹果官网下载并安装。

步骤 1:打开脚本编辑器

打开脚本编辑器,可以点击 Launchpad,然后找到并点击“脚本编辑器”图标。也可以在访达中找到脚本编辑器,路径为“应用程序”>“实用工具”>“脚本编辑器”。

步骤 2:创建新脚本

在脚本编辑器中,点击“文件”>“新建”以创建新脚本。也可以使用键盘快捷键 Command + N 来创建新脚本。

步骤 3:编写脚本

在脚本编辑器中,输入以下脚本:

-- 选中信息应用
tell application "Messages"
    activate
end tell

-- 定义需要删除的信息
set messageToDelete to {"Message 1", "Message 2", "Message 3"}

-- 循环删除信息
repeat with i from 1 to (count of messageToDelete)
    set messageName to item i of messageToDelete
    tell application "System Events"
        -- 选择信息
        keystroke "n" using {command down}
        delay 0.5
        tell application "Messages"
            set conversationList to (every conversation whose name is messageName)
            repeat with j from 1 to (count of conversationList)
                set conversation to item j of conversationList
                select conversation
                delay 0.5
                -- 按下 Backspace 键
                key code 51
                delay 0.5
            end repeat
        end tell
    end tell
end repeat

-- 退出信息应用
tell application "Messages"
    quit
end tell

步骤 4:运行脚本

在脚本编辑器中,点击“运行”按钮以运行脚本。也可以使用键盘快捷键 Command + R 来运行脚本。

步骤 5:验证结果

脚本运行完成后,信息应用将被关闭。重新打开信息应用,你将看到之前选定的信息已经全部被删除。

注意:

  • 在运行脚本之前,请确保已经备份了你的信息数据。
  • 请谨慎使用本脚本。如果你不小心删除了错误的信息,你可能无法恢复它们。