Macのフォルダ内のファイルを定期的に削除する


2

Macの標準ユーザーアカウントのドキュメントとデスクトップフォルダの内容が毎日真夜中に削除されるようにします。どうすればこれを実現できますか?

回答:


5

〜/ライブラリ/ LaunchAgents / me.lri.clear.desktop.and.documents.plist

<?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>me.lri.clear.desktop.and.documents</string>
    <key>ProgramArguments</key>
    <array>
        <string>osascript</string>
        <string>-e</string>
        <string>say "lol"</string>
        <!-- <string>tell application "Finder"
        move items of desktop to trash
        move items of (path to documents folder) to trash
        end tell</string> -->
    </array>
    <key>StartInterval</key>
    <integer>5</integer> <!-- every 5 seconds -->
    <!-- <key>StartCalendarInterval</key>
    <dict>
        <key>Hour</key>
        <integer>23</integer>
        <key>Minute</key>
        <integer>0</integer>
    </dict> --> 
    </dict>
</plist>

エージェントは、ログアウトしてから再度ログインした後、または実行した後にロードされます。 launchctl load ~/Library/LaunchAgents/me.lri.clear.desktop_and.documents.plist

見る man launchctl そして man launchd.plist 詳細については。


もう一つの選択肢はあなたのcrontabにこのようなものを追加することです。

0 0 0 * * osascript -e 'tell app "Finder"' -e 'move items of desktop to trash' -e 'move items of (path to documents folder) to trash' -e 'end'

(あなたはそれを ~/.crontabその後、実行します crontab ~/.crontab


「笑」と言う?あなたの台本は悪です!
Daniel Beck

「ムアハハハ」
Andrew Lambert

0

それはかなり単純なはずです クーロン 指定されたディレクトリーの内容を削除するシェル・スクリプトを呼び出すジョブ

私はMacを持っていませんが、MacにはBASH互換のシェルが付属していると思います。だからこのようなもの:

#!/bin/bash
rm /path/to/directory1
rm /path/to/directory2
...etc...

Macシェルが従来の* nixファイルパススキーマ(/ blah / blah)を使用しているのか、それともFinderが使用しているスキーマ(blah:blah)を使用しているのかわかりません。それはあなたが調べることができるものです。の rm あなたがそれをしたい場合、コマンドはサブディレクトリまたはその内容を削除することに失敗します -r スイッチ。


OS XのUnix-yビットは標準のスラッシュセパレータを使います。
Lawrence Velázquez

@LawrenceVelázquez知っておくと良い。ありがとう。
Andrew Lambert
弊社のサイトを使用することにより、あなたは弊社のクッキーポリシーおよびプライバシーポリシーを読み、理解したものとみなされます。
Licensed under cc by-sa 3.0 with attribution required.