• Hi, I’m back... and yesterday i was recalling this forum, i just came by to tell you my experience.

    *Now it works and was easy to solve but difficult to get it there, because it seems is some app issue. I had to close and re-open the app as if it needs to refresh all variables or objects, idk.
    I noticed it when i was working on this code, it worked okay and then i took a 15mins break, but when i was back to Pythonista; it suddenly stop working... <<why?! If it was already working just fine>> Well i debugged it and i could see ‘contacts.Person()’ fields being changed and ‘saved’ correctly, BUT those updates only showed up within Pythonista, and not in My Contacts app. It was like if Pythonista retrieved all my contacts from a different app or memory.
    Well, after trying changing the code here and there without any success, i just closed the app(slide up) and re-open it, and voila, my code was working again, all contacts’ updates were mirrored in my contacts app.

    Now, the code i was testing and worked fine as example. (You can use get_all_people() instead of find() )

    import clipboard primer_valor_de_lista = 0 curr_cb = clipboard.get() temp_contact = contacts.find('Temporal') person = temp_contact[primer_valor_de_lista] #print(person.first_name) #converted = int(curr_cb) #print(curr_cb) person.phone = [(contacts.MAIN_PHONE, curr_cb)] #temp_contact[primer_valor_de_lista]=person contacts.save() #print(person.phone[0]) Insert Code Here
  • cool, thanks, there must be a setter property on person.phones that does the work,
    changes to bits of the phone list are not seen unless you do person.phone = <updated list>

  • @my4paws I also learned something, as usual in this forum, thanks to guys like @ccc and a lot of other ones...

  • @omz said:

    I can't test this right now, but I have a suspicion that you need to set the argtypes and restype properties of the ObjC method manually. The derivation from the protocols argument doesn't always work reliably if the protocol isn't used as part of Pythonista itself. I hope this makes sense.

    I completely forgot about argtypes and restype honestly. It makes sense, I will keep trying to find out correct argtypes. Thanks for your suggestion. Please let me know once you test.

  • In case anybody has a similar issue to mine, here's a link to a gist showing the completed script: add-contact.py.

  • @ccc , out of interest, did you try your func without passing 'vcard' to the filter? Puts a big strain on the timing

  • This looks awesome for your first script! My first script is lame compared to this one lol. All it does is detect if you have a link to a tweet in your clipboard and then it likes it using your account.

  • Thank you @omz, the code you shared is working perfectly

  • you have to re-assign the email attribute of the Person object. Modifying the list in-place has no effect, because the Person object cannot detect changes in that list (it's just a snapshot copy).

    Try something like this:

    import contacts people = contacts.get_all_people() print people[0].full_name emails = people[0].email emails.append((u'$!<Other>!$', u'test@test.com')) people[0].email = emails # !!! contacts.save()
Internal error.

Oops! Looks like something went wrong!