Don’t wanna get your wife angry just because of let her wait so long for a dinner? This program is for you. It’s a guide to build the simple application that automatically sends SMS to your wife at a specific time if you need to stay longer at the office.
![](https://zen8labs.b-cdn.net/wp-content/uploads/2024/03/zen8labs-happy-programmer-conversation-1-.png)
Get Twilio account
Register an account at: https://www.twilio.com, the service lets you send the SMS via REST API. During trial period, you could get 10$ — enough free messages; then you get charged with low fare later (~0.01–0.05$ for each SMS).
Setup Twilio
Now replace this command with your information above, replace + in the phone number with %2B.
curl -s -X POST “https://api.twilio.com/2010-04-01/Accounts/{ASID}/SMS/Messages.xml" -d From=”{SENDER}” -d To=”{RECEIVER}” -d Body=”{MESSAGE}” -u {KSID}:{KSECRET}
curl -s -X POST “https://api.twilio.com/2010-04-01/Accounts/{ASID}/SMS/Messages.xml" -d From=”{SENDER}” -d To=”{RECEIVER}” -d Body=”{MESSAGE}” -u {KSID}:{KSECRET}
Then run.
curl -s -X POST “https://api.twilio.com/2010-04-01/Accounts/ACa225474ed0119821diekxu29dvcc30bfe/SMS/Messages.xml" -d From=”%2B1914–595–1437" -d To=”%2B988999888" -d Body=”I'm busy today and might come home late. Love you my dear” -u SKe893oxkdks5c9bc4fea37b1de9f1de396:sJRZaW8fn2M0kalxielxmq9ZM15Z1czW3R
curl -s -X POST “https://api.twilio.com/2010-04-01/Accounts/ACa225474ed0119821diekxu29dvcc30bfe/SMS/Messages.xml" -d From=”%2B1914–595–1437" -d To=”%2B988999888" -d Body=”I'm busy today and might come home late. Love you my dear” -u SKe893oxkdks5c9bc4fea37b1de9f1de396:sJRZaW8fn2M0kalxielxmq9ZM15Z1czW3R
Got it? We are almost done.
Setup a cronjob
You can send SMS to your wife by only 1 command; now get it automated.
1. Create a file sweet_sms_to_darling.sh, put the command above.
#!/bin/bash # Script to send an SMS alert via Twilio. curl -s -X POST “https://api.twilio.com/2010-04-01/Accounts/ACa225474ed0119821diekxu29dvcc30bfe/SMS/Messages.xml" -d From=”%2B1914–595–1437" -d To=”%2B988999888" -d Body=”I'm busy today and might come home late. Love you my dear” -u SKe893oxkdks5c9bc4fea37b1de9f1de396:sJRZaW8fn2M0kalxielxmq9ZM15Z1czW3R
# Script to send an SMS alert via Twilio.
curl -s -X POST “https://api.twilio.com/2010-04-01/Accounts/ACa225474ed0119821diekxu29dvcc30bfe/SMS/Messages.xml" -d From=”%2B1914–595–1437" -d To=”%2B988999888" -d Body=”I'm busy today and might come home late. Love you my dear” -u SKe893oxkdks5c9bc4fea37b1de9f1de396:sJRZaW8fn2M0kalxielxmq9ZM15Z1czW3R
2. Get it executable, and run at 18:30 every day.
MacBook-Pro:twilio tom$ chmod 775 sweet_sms_to_darling.sh MacBook-Pro:twilio tom$ vi /etc/crontab
MacBook-Pro:twilio tom$ chmod 775 sweet_sms_to_darling.sh
MacBook-Pro:twilio tom$ vi /etc/crontab
Add this line, correct your file path, 18, 30 is the hour and minute triggers this bash script.
30 18 * * * ~/Desktop/twilio/sweet_sms_to_darling.sh
30 18 * * * ~/Desktop/twilio/sweet_sms_to_darling.sh
3. Save this file and add to cronjob. That’s all.
MacBook-Pro:twilio tom$ crontab /etc/crontab
MacBook-Pro:twilio tom$ crontab /etc/crontab
OK, now when your computer is up on 18:30, it automatically send the SMS to your wife.
Don’t worry about she get angry. Now work.
Please don’t put this job on server — it’s always up ?
It’s general idea of building the application, you could do it in others platform like Windows with BAT file and scheduled task. Another simpler and specific version for Mac is coming soon ? Part 2