Applescript & SMS Server Tools

Uncategorized Add comments

I’ve set up SMS Server Tools on my Mac Mini so that I can send text messages from my PC and I thought someone might be able to use the Applescript I’ve created or even suggest a better way of doing things.

If you’re not familiar with SMS Server Tools it’s a really great utility for sending text messages from your PC (I use the term generically) it works on (almost?) all UNIXs and Windows too. It works by having folders which it monitors for text message files and then sending them via the phone. It was very easy to set up just download the source, make, make install, edit the config file and away you go.

I set it up so I could send myself text alerts when I get new emails. I did have it set up last year on my Gentoo machine and I used a bash script to process mail passed from Kmail. This time I’m using my Mac Mini and OS X with Apple’s Mail and a bit of applescript.

The biggest difference between the way Kmail and Mac Mail does things is that Kmail would run the bash script each time a message matched a given rule. Mail passes a collection of messages to the applescript that match the rule.

SMS File Format

The SMS files are just plain text files with unique file names;

To: 447xxxxxxxxx

Message Text goes here

Notice how the phone number you’re sending the message to is international format without the leading + and that there is a blank line inbetween the number and the message text.

The Applescript

This is the applescript I’m using to send the messages. I don’t have much experience with Applescript so anyone who can see a better way of doing things (especially the writing of the file) then I’d appreciate some feedback.

using terms from application “Mail”
on perform mail action with messages theMessages
repeat with theMessage in theMessages — loop through the messages sent by Mail
–Extract the desired details
set theSubject to subject of theMessage
set theSender to extract address from (sender of theMessage)
set MessageRecipients to get recipients of theMessage
set firstRecipient to item 1 of MessageRecipients
set toAddress to ((address of firstRecipient) as string)

–Create the randomly named file
set dir_prefix to “~/sms/”
set the_file to do shell script “mktemp ” & dir_prefix & “tempfiles/XXXXXX”

–Output the message
do shell script “echo To: 447xxxxxxxxx > ” & the_file
do shell script “echo >> ” & the_file
do shell script “echo From: ” & quoted form of theSender & ” >> ” & the_file
do shell script “echo To: ” & quoted form of toAddress & ” >> ” & the_file
do shell script “echo Subject: ” & quoted form of theSubject & ” >> ” & the_file

–Move the text message to the spool directory
do shell script “mv ” & the_file & ” ” & dir_prefix & “outgoing/”
end repeat
end perform mail action with messages
end using terms from

You can download the script from here. You will need to change the directory variables to suit your setup and you’ll need to replace the mobile number with the one you wish to send the messages to. I decided to edit my /etc/smsd.conf to define the spool folders to be in my home directory.

12 Responses to “Applescript & SMS Server Tools”

  1. klkl Says:

    I’ve noticed that appears to only run rules for messages delivered to the inbox of IMAP accounts. I use server side sieve scripts to organise my mail into sub mailboxes and doesn’t apply this rule to those messages… bummer!

    If anybody knows of a way of getting to apply rules to new mail the server has organised I’d love to hear from you.

  2. klkl Says:

    Also there’s an issue with emails that are sent to ‘undisclosed recipients’ they cause files with no content to be generated. I’m really not that familiar with applescript, it annoys me, and I don’t really have the time to figure this out right now.

    I’ll come back to it when I’ve got time.

  3. Sergey Says:

    Whoa!!! Need some more info on sms server tools (what if I have only a bluetooth phone? Will it run smoothly and reconnect bt connection each time the sms is to be sent or received?). The docs for that server are so spacious. Do not have a gsm phone with me right now, and my cdma one is quite bizarre and doesn’t support at commands (it’s ubiquam u-300). So I’ll try a bit later. How do I set up a script for Adium? I checked the dictionary for that application but can’t find anything that would help me getting the text message to send it to the cell phone…

  4. klkl Says:

    Well for me it was a simple matter of plugging the phone into my mac via usb and finding out which device it was assigned to then setting that variable in the conf.

    I’m not sure about bluetooth, I’ve never tried it, nor a cdma phone, I didn’t have to use any AT commands.

    As for Adium, I just deleted it… couldn’t get on with it so you’re best of searching for adium and applescript.

  5. Firgie Says:

    Hi, klkl!

    I’ve just downloaded, configured, made, and installed the SMS Server Tools 3 on my MacBook with Mac OS X 10.4.11 and I’m using a HUAWEI HSDPA modem to test it.But I’m still got error on the log file. Could you share your primary configuration parameters on the /etc/smsd.conf file for it? Like what is the device name for it? There’s no ttyUSB0 (I’m guessing it’s on Linux only). Can I use the modem as sms gateaway while still using it as a HSDPA modem? I’m quite a newbie of this thing.

  6. Mona Says:

    Hi Firgie,

    I have the same setup. were you able to configure sms tools on a mac with HUAWEI. If yes could you please share your /etc/smsd.conf

  7. Noel Maleszka Says:

    This article is certainly the most informative on this worthwhile topic. I concur with your conclusions and will most certainly look forward to your forthcoming updates. Saying thanks will not just be sufficient, for the wonderful thought you put in your writing. I will immediately grab your rss feed to stay privy of any updates. Great work and much success in your business dealings!

  8. Glassafm Says:

    ???????,??????????! .

  9. Scannerukn Says:

    ???????,??????????! .

  10. Premiumiai Says:

    ???????,??????????! .

  11. Backlitlow Says:

    ???????,??????????! .

  12. Interfacehov Says:

    ???????,??????????! .

Leave a Reply

WP Theme & Icons by N.Design Studio | Akismet has gobbled 348,921 spam comments...Mmmm Tasty :-)
Entries RSS Comments RSS Log in