1

I try to import csv file in my contacts in a new group with javascript or applescript (I will appreciate help in JS). what I've tried:(I tried lot combinaison of this command)

var contact = Application("Contacts");
var group = contact.Group({
'name':'test'})
var personne = contact.Person()


contact.add(contact.Person())
var g = contact.Group({name : "test"})
contact.add(g)

I tried first to create a new group but nothing become visible in adress book.app I aim to do File -> new group(cmd+maj+n) and this new group file->import (cmd +o) but with javascript.

jackjr300
  • 7,111
  • 2
  • 15
  • 25
Et7f3XIV
  • 562
  • 1
  • 7
  • 20

1 Answers1

1

You must use the push() command to add an new object (group, person, ...) to the application.

Use the save() command to show the new object in the application.

This script add a new person in a new group:

var contact = Application("Contacts")

var g = contact.Group({name : "test"})
contact.groups.push(g)// add a new group to the application
contact.save() // save and show the group in the application


var personne = contact.Person({firstName : "Ben", lastName : "zzzzzz", organization : "abcd", jobTitle : "President"})
contact.people.push(personne)// add a new person to the application
contact.add(personne, {to : g}) // add personne to the group
contact.save() // save and show the new person in the new group
jackjr300
  • 7,111
  • 2
  • 15
  • 25
  • The first part of my problem is solved (add Group) : Thanks, but the personne is added to group and ~3s after the group become empty. did I have miss something? – Et7f3XIV Jan 07 '18 at 15:57
  • I've investigated and saw that when disable all my accounts (settings, internet accounts, and I uncheck adress book for all account the script work perfectly). What can cause this bug? – Et7f3XIV Jan 07 '18 at 19:05