0

Hopefully, I can explain what I am attempting to achieve. I have an email address designated for SMS ([email protected]) This account gets check via Mail (apple V13). I have a rule that every message does an Applescript as follows:

    using terms from application "Mail"
    on perform mail action with messages newMessages
        repeat with newMessage in newMessages
            tell application "Mail"
                set theText to ""
                set theSubject to ""
                repeat with theMessage in selectedMessages
                    set theText to theText & (content of theMessage) as string
                    set theSubject to theSubject & (subject of theMessage) as string                    
                    tell application "Messages"
                        activate --steal focus
                        set targetBuddy to theSubject
                        set targetService to id of service "SMS"
                        set textMessage to theText
                        set theBuddy to buddy targetBuddy of service id targetService
                        send textMessage to theBuddy
                    end tell
                end repeat
            end tell
        end repeat
    end perform mail action with messages
end using terms from

Unfortunately it does not work and for the life of me I dont understand why.
Could I ask for some assistance?

5
  • You've got a Messages tell block inside a Mail tell block, which is going to be a potential cause for problems. I'd suggest taking it outside the entire on perform mail action handler, and sticking it in its own handler that you can call. I can't say for sure that it's definitely the source of your problem, but you also don't say anything about how this script fails to work, i.e. what should it do, what does it do currently, and what errors arise and where in the script do they occur, etc. etc.
    – CJK
    Dec 30, 2019 at 13:04
  • Ah: repeat with theMessage in selectedMessages This references the variable selectedMessages, which does not appear anywhere else in the script, so either this isn't the entire script, or this variable hasn't been declared/defined.
    – CJK
    Dec 30, 2019 at 13:06
  • Thank you @CJK. I am very green in this space and I appreciate the help. I am attempting to activate this rule (with mail rules for every message) to run the script to do the following: Take the information from the email received and send an Imessage. (which works if run independently) the issue I find is it is not running it with the rule in place.
    – Frenchy
    Jan 2, 2020 at 1:56
  • using terms from application "Mail" on perform mail action with messages TheMessages for rule theRule repeat with aMessage in TheMessages tell application "Mail" set theText to "" set theSubject to "" set theText to theText & (content of theMessage) as string set theSubject to theSubject & (subject of theMessage) as string
    – Frenchy
    Jan 2, 2020 at 2:12
  • end tell end repeat end perform mail action with messages tell application "Messages" activate --steal focus set targetBuddy to theSubject set targetService to id of service "SMS" set textMessage to theText set theBuddy to buddy targetBuddy of service id targetService send textMessage to theBuddy end tell end using terms from
    – Frenchy
    Jan 2, 2020 at 2:12

0

You must log in to answer this question.

Browse other questions tagged .