Periodic update of macports Yet again it happened. I forgot to update my macports and I'm wasting hours...

How can I automatically run

sudo port -v selfupdate
sudo port -v upgrade outdated


Let say every week? Note that it has to be ran as root... 

How do you maintain you macports up-to-date?

Is something like suggested here is a good idea?
The usual way to run commands at regular intervals is you use launchd

An easy way is to use tools like Lingon X or LaunchControl to maintain the  daemon/agent configuration file.

You can also do this without the tool by creating the file with a plain editor. To run as root you will need a .plist file in /Library/LaunchDaemons. This needs you to provide the script and its arguments and will run as root.

In your case create a script to run both updates

port -v selfupdate
port -v upgrade outdated


Apple gives an example to run a script called happybirthday as below



&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
  "http://www.apple.com/DTDs/PropertyList-1.0.dtd"&gt;
&lt;plist version="1.0"&gt;
&lt;dict&gt;
    &lt;key&gt;Label&lt;/key&gt;
    &lt;string&gt;com.example.happybirthday&lt;/string&gt;
    &lt;key&gt;ProgramArguments&lt;/key&gt;
    &lt;array&gt;
        &lt;string&gt;happybirthday&lt;/string&gt;
    &lt;/array&gt;
    &lt;key&gt;StartCalendarInterval&lt;/key&gt;
    &lt;dict&gt;
        &lt;key&gt;Day&lt;/key&gt;
        &lt;integer&gt;11&lt;/integer&gt;
        &lt;key&gt;Hour&lt;/key&gt;
        &lt;integer&gt;0&lt;/integer&gt;
        &lt;key&gt;Minute&lt;/key&gt;
        &lt;integer&gt;0&lt;/integer&gt;
        &lt;key&gt;Month&lt;/key&gt;
        &lt;integer&gt;7&lt;/integer&gt;
        &lt;key&gt;Weekday&lt;/key&gt;
        &lt;integer&gt;0&lt;/integer&gt;
    &lt;/dict&gt;
&lt;/dict&gt;
&lt;/plist&gt;