首页 > 解决方案 > iMessage Apple 脚本 - 尝试向可以是全名或号码的目标发送消息

问题描述

我正在尝试接受一个目标并让 if 语句确定它是电话号码还是全名。我似乎无法弄清楚如何从 iMessage 应用程序中找到全名。这是我到目前为止得到的,似乎只是当目标是非整数时。

use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions

    launch application "Messages"
    tell application "Messages"
        set targetService to 1st account whose service type = iMessage
        set targetPhoneNumber to "Alejandro Cervantes"
        set targetMessageToSend to "Test"
        
        if targetPhoneNumber is not integer then
            set targetName to get id of account of participant targetPhoneNumber
            set targetBuddy to participant targetPhoneNumber of targetService whose full name is targetPhoneNumber
        else
            set targetBuddy to participant targetPhoneNumber of targetService
        end if
        
        set targetMessage to targetMessageToSend
        send targetMessage to targetBuddy
        
    end tell

标签: iosmacosapplescriptbots

解决方案


推荐阅读