Go Back   The macosxhints Forums > OS X Help Requests > Applications



 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
Old 07-30-2004, 06:12 PM   #1
efrey
Prospect
 
Join Date: Jul 2004
Posts: 1
Applescript: SMS Sender Clickatell

Hi all

I have created a script to send sms to www.clickatell.com, an inexpensive sms sender company.They offer an email to sms gateway.

Unfortunately, there are some unsolved problems:

-- wish list 1: Send to all selected contacts within addressbook (or, less flexible: to group) --
-- wish list 2: optimisation of international / local (+4179XXXXX/004179XXXXX/079XXXXX) problem to make this more flexible and usable for other people --
-- wish list 3: live updating sms length in the sms writing dialog --
-- with list 4: general optimisation of code to make it quicker --

Could you please have a look at the script and tell me what you think and what you would change?

-------------------

-- clickatell sms sender version 0.1 - myemail@mydomain.com --
-- clickatell service is available at www.clickatell.com --

-- this script has to be stored in the /Library/Address Book Plug-Ins to operate correctly --
-- this script still needs modification for anybody to run --

-- any help to make the following updates would be greatly appreciated: --
-- wish list 1: Send to all selected contacts within addressbook (or, less flexible: to group) --
-- wish list 2: optimisation of international / local (+4179XXXXX/004179XXXXX/079XXXXX) problem to make this more flexible and usable for other people --
-- wish list 3: live updating sms length in the sms writing dialog --
-- with list 4: general optimisation of code to make it quicker --

-------------

-- first we define in which tab of the addressbook this script should appear --

using terms from application "Address Book"
on action property
return "phone"
end action property

on action title for p with e
return "sms_send"
end action title

on should enable action for p with e
return label of e is "mobile"
end should enable action

-- now we display the dialog to write the sms including sms length (because sms can only be 160 chars long on clickatell) --

on perform action for p with e
copy value of e as string to phone_string
copy remove_blanks(phone_string) to phone_string
set l to the length of phone_string
set phone_string to (characters 2 through l of phone_string) as string
set sms_string to ""
repeat
display dialog "SMS-Text (length " & (the length of sms_string as string) & " chars):" default answer sms_string buttons {"Cancel", "OK"} default button 2
set the sms_string to the text returned of the result
if (the length of the sms_string is less than 160) and (the length of sms_string is greater than 0) then exit repeat
end repeat

-- now to some chopping and shortening, this is due to the length restriction of lines of clickatell in the email to be sent --

set l2 to the length of sms_string
if (the length of the sms_string is less than 66) then
set begintext to "text:" & (characters 1 thru l2 of sms_string) as string
set midtext to ""
set endtext to ""
end if
if (the length of the sms_string is greater than 66) then
set begintext to "text:" & (characters 1 thru 66 of sms_string) as string
set midtext to "text:" & (characters 67 thru l2 of sms_string) as string
set endtext to ""
end if
if (the length of sms_string is greater than 132) then
set begintext to "text:" & (characters 1 thru 66 of sms_string) as string
set midtext to "text:" & (characters 67 thru 132 of sms_string) as string
set endtext to "text:" & (characters 133 thru l2 of sms_string as string)
end if

-- we now create a new email with the text to be sent to clickatell --
-- the XXX portion of this part are to be replaced by YOUR actual clickatell account data --
-- the +41 part is the actual data of switzerland, for germany it would be +49 etc... --
-- in my addressbook the mobile numbers are just stored in format: 079 XXX XX XX, if all your mobile numbers contain the country code, (+41 for example) you have to modify this script (pending item) --

tell application "Mail"
set newMessage to make new outgoing message with properties ¬
{subject:"sms", content:"api_id:XXXXXX
user:XXXXXX
password:XXXXXX
from:+41XXXXXX
to:41" & phone_string & "
" & begintext & "
" & midtext & "
" & endtext}
tell newMessage
set visible to true
set sender to "XXXXXXXXX <XXX@XXX.com>"
make new to recipient at end of to recipients with properties ¬
{name:"sms@messaging.clickatell.com", address:"sms@messaging.clickatell.com"}
send newMessage
end tell



end tell

return true
end perform action
end using terms from

-- here we have a portion to remove the blanks --

on remove_blanks(SMSString)
set phone_string to replace_chars(SMSString, " ", "")
return phone_string
end remove_blanks

-- here we have a portion to replace chars --

on replace_chars(this_text, search_string, replacement_string)
set AppleScript's text item delimiters to the search_string
set the item_list to every text item of this_text
set AppleScript's text item delimiters to the replacement_string
set this_text to the item_list as string
set AppleScript's text item delimiters to ""
return this_text
end replace_chars
efrey is offline   Reply With Quote
 

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 02:34 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Site design © Mac Publishing LLC; individuals retain copyright of their postings
but consent to the possible use of their material in other areas of Mac Publishing LLC.
You Rated this Thread: