• 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: Kaydell Leavitt <email@hidden>
  • Date: Mon, 24 Jun 2013 16:49:06 -0600

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) Help/Unsubscribe/Update your Subscription: Archives: http://lists.apple.com/archives/applescript-users This email sent to email@hidden
  • Follow-Ups:
    • Re: add contact to carddav with applescript
      • From: Shoddy <email@hidden>
References: 
 >add contact to carddav with applescript (From: Shoddy <email@hidden>)

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