How to start new conversation in iMessage using AppleScript?

后端 未结 2 1715
礼貌的吻别
礼貌的吻别 2020-12-16 14:02

So I\'m working on creating an applescript which essentially automates sending an imessage. What I have working now is:

on run {msg, phoneNum}
    tell appl         


        
相关标签:
2条回答
  • 2020-12-16 14:10

    There are many ways to do it.

    First example:

    on run {targetBuddyPhone, targetMessage}
        tell application "Messages"
            set targetService to 1st service whose service type = iMessage
            set targetBuddy to buddy targetBuddyPhone of targetService
            send targetMessage to targetBuddy
        end tell
    end run
    

    Second example:

    tell application "Messages"
        set targetBuddy to "+18001234567"
        set targetService to id of 1st service whose service type = iMessage
        repeat
            set textMessage to "Hello pal!"
            set theBuddy to buddy targetBuddy of service id targetService
            send textMessage to theBuddy
            delay (random number from 10 to 30)
        end repeat
    end tell
    
    0 讨论(0)
  • 2020-12-16 14:18

    My solution is to tell Applescript to press "Command + N", which is the shortkey for "Start a new conversation"

    activate application "Messages"
       tell application "System Events" to tell process "Messages"
       key code 45 using command down           -- press Command + N to start a new window
       keystroke "<replace with phone number>"  -- input the phone number
       key code 36                              -- press Enter to focus on the message area 
       keystroke "<replace with message>"       -- type some message
       key code 36                              -- press Enter to send
    end tell
    

    This script will start a new conversation and send the message to the phone number through iMessage

    0 讨论(0)
提交回复
热议问题