Skip to content

Instantly share code, notes, and snippets.

@psenger
Last active January 18, 2024 21:49
Show Gist options
  • Save psenger/165de1bfd7af4a2fda4196d6cf51bc26 to your computer and use it in GitHub Desktop.
Save psenger/165de1bfd7af4a2fda4196d6cf51bc26 to your computer and use it in GitHub Desktop.
[How to "Action" when a Mac Reboot] #MacOS

How to "Action" when a Mac Reboots

If your Mac reboots, and you want to be notified that it has rebooted.

How to launch a Script when your mac reboots

Create a .plist file at /Library/LaunchDaemons/com.YOUR_COMPANY.rebootnotification.plist. Change YOUR_COMPANY to your domain name in the .plist file. The contents will look like the following, change /path/to/your/script.sh to your script. This .plist file and the /path/to/your/script.sh should be owned by root:wheel my advise is to make it only executable by root. I take no responsiblities for any Security issues.

<?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.example.rebootnotification</string>
   <key>ProgramArguments</key>
   <array>
       <string>/path/to/your/script.sh</string>
   </array>
   <key>RunAtLoad</key>
   <true/>
</dict>
</plist>

Scripts to send a message to slack

Method 1: script to post a message

curl -H "Content-type: application/json" \
--data '{"channel":"C123456","blocks":[{"type":"section","text":{"type":"mrkdwn","text":"Your message here."}}]}' \
-H "Authorization: Bearer YOUR_SLACK_API_TOKEN" \
-X POST https://slack.com/api/chat.postMessage

Method 2: script to post to a webhook

curl -X POST -H 'Content-type: application/json' --data '{"text": "Your message here."}' https://hooks.slack.com/services/YOUR/WEBHOOK/URL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment