I try to get all my iMessage contacts from the app "Messages" via JXA scripting. When I assign the array to a variable I can only work with the first 40 objects. But the array has a length of 147.
var Messages = Application("Messages")
var buddies = Messages.buddies()
console.log(buddies.length) // == 147
When I go to "replies" tab at the bottom of the script editor, I can see all 147 buddies:
app.buddies()
--> [app.buddies.byId(...), ...]
But when I try to work with an object from the array with index greater than 39, I get an error -1728 (Object not found) e.g.
console.log(buddies[45].id())
Whats wrong? And what is the proper way to get the ids of all buddies?
There is a difference, of course, between
Messages.buddies()
(a function call returning an array), and
Messages.buddies
(a reference to the buddies object).
You should be able to get a full list of ids by calling the .id()
method just once, directly on the .buddies
object.
(() => {
'use strict';
const
Messages = Application("Messages"),
refBs = Messages.buddies;
return refBs.id();
})();