AppleScript iMessage to SMS accounts not working MacOSX Sonoma

22 Views Asked by At

Trying to write a script that parses through an excel file and sends SMS/iMessage to all listings in the file. Script works for all except SMS type. Please help.

set file_Name to "/Target.xlsx" set messageToSend to "Testing an app I wrote to sent mass text messages. Just ignore." set greeting to "Good afternoon"

tell application "Microsoft Excel" activate open file_Name

tell active sheet
    tell used range
        set RowCount to count of rows
    end tell
    log "RowCount is " & RowCount
end tell -- active sheet   

end tell -- application

repeat with theIncrementValue from 1 to RowCount tell application "Microsoft Excel"

    tell active sheet
        set theCell to "A" & theIncrementValue & ":A" & theIncrementValue
        log "theCell is " & theCell
        set phone to string value of range theCell as string
        log "number  is " & phone
        
        set theCell to "B" & theIncrementValue & ":B" & theIncrementValue
        log "theCell is " & theCell
        set recipient to get value of range theCell as string
        log "Name is " & recipient
        
        tell application "Messages"
            set phoneNumber to phone
            set persMessageToSend to greeting & " " & recipient & ", " & messageToSend
            
            try
                set iMessageService to (1st account whose service type = iMessage)
                set iMessageBuddy to participant phoneNumber of iMessageService
                send persMessageToSend to iMessageBuddy
                log ("sent as iMessage to: " & phoneNumber)
            on error
                try
                    set iMessageService to (1st account whose service type = SMS)
                    set iMessageBuddy to participant phoneNumber of iMessageService
                    send persMessageToSend to iMessageBuddy
                    log ("sent as SMS to: " & phoneNumber)
                on error
                    log ("ERROR: COULD NOT SEND TO: " & phoneNumber)
                end try
            end try
        end tell
    end tell -- active sheet
end tell -- application  

end repeat

Error: Could not send fires every time when sending to an SMS number.

0

There are 0 best solutions below