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.
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
- Buy a number at: https://www.twilio.com/console/phone-numbers/incoming. It costs 1$, Twilio uses this number to send SMS. Call it SENDER.
- Verify your wife’s phone number (with country code like +84 988 999 888) at: https://www.twilio.com/console/phone-numbers/verified (to make sure you don’t spam anyone). Call it RECEIVER.
- Create API key at: https://www.twilio.com/console/dev-tools/api-keys. You can get API key and secret key here. Call them KSID and KSECRET.
- Go to https://www.twilio.com/console and get your account SID. Call it ASID.
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}
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="Anh ban roi, ve muon day" -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="Anh ban roi, ve muon day" -u SKe893oxkdks5c9bc4fea37b1de9f1de396:sJRZaW8fn2M0kalxielxmq9ZM15Z1czW3R
2. Get it executable, and run at 18:30 every day.
MacBook-Pro:twilio hien$ chmod 775 sweet_sms_to_darling.sh MacBook-Pro:twilio hien$ 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
3. Save this file and add to cronjob. That’s all.
MacBook-Pro:twilio hien$ 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 😉