PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, July 12, 2022

[FIXED] What is a more elegant way to overcome Error: Expecting object specifier. Argument has no object specifier when sending an SMS via Messages via JXA

 July 12, 2022     javascript, javascript-automation, macos, messages     No comments   

Issue

This fails to work

    with (Application("Messages")) { 
            send(text, {to: services["SMS"].buddies[phone]}) 
    }

with Error: Expecting object specifier. Argument has no object specifier.

text is valid and not null. phone is valid and not null. If I hard code the values it works. I decided to try 'dynamic' hard coding which worked.

    command = 'with (Application("Messages")) { send("' + text + '", {to: services["SMS"].buddies["' + phone + '"]}) } ;' ;
    eval(command) ;

Is there a more elegant way of overcoming this? Why would eval work but the code with the variables not?


Solution

Breaking the code out into smaller pieces helps me.

var text="foo"
var phone="+14159999999"
var Messages = Application('Messages')
var service = Messages.services[0]
var recipient = service.buddies.byName(phone, {
    of: service
})

Messages.send(text  , {
    to: recipient
})


Answered By - JakeCigar
Answer Checked By - Gilberto Lyons (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing