title: iMessage Apple script - Trying to send a message to target that can be the Full Name or Number
body: <p>I am trying to take in a target and have an if statement determine if it's a phone number or the full name. I cant seem to figure out how to find the full name from the iMessage app. Here is what I got so far and it seems to just be when the target is a noninteger.</p>
  <pre><code>use AppleScript version &quot;2.4&quot; -- Yosemite (10.10) or later
  use scripting additions
  
      launch application &quot;Messages&quot;
      tell application &quot;Messages&quot;
          set targetService to 1st account whose service type = iMessage
          set targetPhoneNumber to &quot;Alejandro Cervantes&quot;
          set targetMessageToSend to &quot;Test&quot;
          
          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
  </code></pre>