3

I am trying to empty a directory at the end of the day, so I have written the following script:

<?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.my.script.removetemp</string>
    <key>ProgramArguments</key>
    <array>
        <string>rm</string>
        <string>-fr</string>
        <string>/tmp/test/*</string>
    </array>
    <key>StartCalendarInterval</key>
    <dict>
        <key>Minute</key>
        <integer>45</integer>
        <key>Hour</key>
        <integer>23</integer>
    </dict>
</dict>
</plist>

I named it com.my.script.removetemp.plist and placed it in ~/Library/LaunchAgents/, but it doesn’t work.

What am I doing wrong?

0
3

Shell globbing (<string>/tmp/test/👉*👈</string>) is not supported by launchd!

You can either remove the whole folder test <string>/tmp/test</string> or launch a shell script rmtestcontent (in the example /usr/local/bin/rmtestcontent) with the content:

#!/bin/bash

/bin/rm -fr /tmp/test/*

with the 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>com.my.script.removetemp</string>
    <key>ProgramArguments</key>
    <array>
        <string>/bin/sh</string>
        <string>-c</string>
        <string>/usr/local/bin/rmtestcontent</string>
    </array>
    <key>StartCalendarInterval</key>
    <dict>
        <key>Minute</key>
        <integer>45</integer>
        <key>Hour</key>
        <integer>23</integer>
    </dict>
</dict>
</plist>

to empty the directory /tmp/test.

2
  • 1
    👉+1👈 For the diagnosis and the solution I like (since delete requirements get heavier over time, might as well script it) – bmike Feb 8 '20 at 18:42
  • 3
    I wonder how many questions about launchd scripts would be eliminated if everyone used Launch Control? – Seamus Feb 8 '20 at 18:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .