Skip to content

Instantly share code, notes, and snippets.

@hdformat
Last active October 10, 2020 04:52
Show Gist options
  • Save hdformat/8371149b513d0a5779d860812c693289 to your computer and use it in GitHub Desktop.
Save hdformat/8371149b513d0a5779d860812c693289 to your computer and use it in GitHub Desktop.
How to make scheduled Powershell scripts on Mac OS X

create a script named greet.ps1

$ vi greet.ps1
#/usr/bin/env pwsh
write-host "🤡"

edit crontab

$ crontab -e

add a line like below

* * * * * /usr/local/microsoft/powershell/7/pwsh /Users/hdformat/greet.ps1 >/tmp/stdout.log 2>/tmp/stderr.log

save and exit. (Mac OS X apply changed crontab immediatly)

$ crontab -e
crontab: installing new crontab

check if it works

$ tail -f /tmp/stdout.log
🤡
🤡
🤡
🤡
🤡
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment