gpt4 book ai didi

macos - 删除30天以上的下载内容?

转载 作者:行者123 更新时间:2023-12-04 14:09:05 24 4
gpt4 key购买 nike

我正在尝试在automator中创建一个任务,如果〜/Downloads中的文件已超过30天,则会将其移至垃圾箱。

我希望它每天运行。

但是它不起作用,Finder只是挂起并停止响应,我必须从事件监视器中强制退出它。

on run {input, parameters}

tell application "Finder"
set deleteFileList to (files of entire contents of folder alias "Macintosh HD:Users:George:Downloads" whose modification date is less than ((get current date)) - 30 * days)
try
repeat with deleteFile in deleteFileList
delete deleteFile
end repeat
end try
end tell

return input
end run

最佳答案

我将采用另一种方法,并使用 Automator 中可用的一组操作,而不使用 AppleScript

以下工作流程将完成您要完成的工作。

Automator 中,创建一个新的工作流程,添加以下操作:

  • 获取指定的查找器项目
  • 将“下载”文件夹添加到其中。
  • 获取文件夹内容
  • []对找到的每个子文件夹重复
  • 过滤器查找器项目
  • 在以下位置查找文件:
  • 以下所有条件都是正确的
  • 上次修改的日期不是最近30天之内
  • 将Finder项移至废纸

  • 工作流程保存为应用程序,例如: Cleanup Downloads.app

    这应该比我在测试中完成的 AppleScript 版本要快得多。

    苹果的首选方法来安排诸如此类的事情,即使用 launchdlaunchctl

    要每天运行 清理下载,我将执行以下操作:
  • 添加清理将下载到:系统偏好设置> 安全和隐私> 隐私> 可访问性
  • 在以下位置创建用户LaunchAgent:~/Library/LaunchAgents/
  • 示例:com.me.cleanup.downloads.plist作为包含以下内容的XML文件:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
    <plist version="1.0">
    <dict>
    <key>Label</key>
    <string>com.me.cleanup.downloads</string>
    <key>ProgramArguments</key>
    <array>
    <string>/Applications/Cleanup Downloads.app/Contents/MacOS/Application Stub</string>
    </array>
    <key>RunAtLoad</key>
    <false/>
    <key>StartCalendarInterval</key>
    <array>
    <dict>
    <key>Hour</key>
    <integer>10</integer>
    <key>Minute</key>
    <integer>00</integer>
    </dict>
    </array>
    </dict>
    </plist>
  • 根据需要,在Hours下设置MinutesStartCalendarInterval的值。该示例设置为:10:00 AM
  • 终端中,运行以下命令来加载LaunchAgent:
    launchctl load ~/Library/LaunchAgents/com.me.cleanup.downloads.plist

  • 注意:请参见终端机中 launchdlaunchctl的手册页,例如 man launchctl
    或使用具有GUI的第三方实用程序,例如: Lingon X

    注意:我与Lingon X的开发人员无关,但是我是一个满意的客户。

    对您的 AppleScript 代码的一些评论:

    不需要 repeat语句,只需使用:
    move deleteFileList to trash
    current date命令在技术上是在 current application下执行,而不是在 Finder下执行,因为 Finder 无法理解 current date命令。因此,设置变量并在命令中使用该变量。
    set thisDate to get (current date) - 30 * days

    ... whose modification date is less than thisDate

    现在,我不建议您在提议的工作流程中实际使用AppleScript,我只是指出我所遇到的代码中的一些问题。

    关于macos - 删除30天以上的下载内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46421279/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com