• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: add contact to carddav with applescript
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: add contact to carddav with applescript


  • Subject: Re: add contact to carddav with applescript
  • From: Shoddy <email@hidden>
  • Date: Tue, 25 Jun 2013 10:58:05 +1000

Hi Kaydell, 

Thank you for your reply.

The code you sent me does not add the group to the carddav server. it only adds the group to the local machine. 

As for the checks, i do not need to check if the person exists as this is never going to be the case. I have not actually told the whole scenario to make the code a little easier. 

I am actually using java and running the applescript from a java program which imports a csv file and then creates the contacts from the csv file. Prior to doing this, i will delete every contact beforehand as i do not need them. 

i am also exporting my contacts from ActiveDirectory to csv which is handled in another program. 

as for the applescript. i only need it to be able to add the contact to the carddav server which is becoming a very difficult task. i have tried my best friend google and he can't help me :(

However i am willing to share my answer to this problem because surely someone has needed to do it before. 

Cheers
Brendon




On Tue, Jun 25, 2013 at 8:49 AM, Kaydell Leavitt <email@hidden> wrote:
Hi Brendon,

I took a look at your code.  I don't think that I have the whole answer, but I was getting
an error adding a group and I don't have CardDAV, but I did get the code to work.

tell application "Contacts"
set fullName to {first name:"Joe", last name:"Bloe"}
# create a new person object
# TODO: If there is already a person with the same first and last name, it would
# be good to ask the user for a confirmation before creating a new person
set thePerson to make new person with properties fullName
make new phone at end of phones of thePerson with properties {label:"mobile", value:"0422123456"}
make new email at end of emails of thePerson with properties {label:"Work", value:"email@hidden"}
# create a group called "TestGroup" (if it doesn't already exist) 
set theGroupName to "TestGroup"
if not (group theGroupName exists) then
set theGroup to make new group with properties {name:theGroupName}
end if
# add thePerson to theGroup
add thePerson to group theGroupName
# save all changes
save
end tell

I think that it is helpful to check if a group by that name already exists before trying
to create a group with the same name.

I think too, that when there is already a person with the same first and last
names that the script should ask the user for a confirmation before adding
a new person with the same name as an existing person in Contacts.
But, I wasn't able to do this.

-- Kaydell
http://learnmacprogramming.com

On Jun 23, 2013, at 5:08 PM, Shoddy <email@hidden> wrote:

Hi all,

Im fairly new to applescript, although i have successfully added a new contact to the contacts app locally however i can not get it to add the contact to the carddav account or in the group of the carddav account. 

My code so far is

tell application "Contacts" 
set thePerson to make new person with properties{first name:"Joe", last name:"Bloe"} 
make new phone at end of phones of thePerson with properties{label:"mobile", value: "0422123456"}
make new email at end of emails of thePerson with properties{label:"Work", value: "email@hidden"}
save 
end tell

If i try to do 

add thePerson to group "TestGroup"

With TestGroup being a group in the carddav account the error i get is
Contacts got an error: You can only add a person to a group.

The machine i am using is the carddav server as well. 

I am also using the latest version of os x. 10.8.4 with all software updates completed. 

With Thanks
Brendon Schodel

--
Shoddy
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden




--
Shoddy
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

References: 
 >add contact to carddav with applescript (From: Shoddy <email@hidden>)
 >Re: add contact to carddav with applescript (From: Kaydell Leavitt <email@hidden>)

  • Prev by Date: Re: assigning properties of an object in a loop, in a tell block
  • Next by Date: unresponsive apps and applescript
  • Previous by thread: Re: add contact to carddav with applescript
  • Next by thread: assigning properties of an object in a loop, in a tell block
  • Index(es):
    • Date
    • Thread