thanks heaps, paul.
scripts works excellent!
cheers, leo
----- Original Message -----
Sent: Sunday, November 28, 2004 6:32
AM
Subject: Re: Address book: how to create
a copy of a person?
On 11/27/04 6:18 AM, "olli" <email@hidden>
wrote:
with applescript i want to create a copy of a person
in the address book.
i tried: tell application
"Address Book" set source_p to item 1 of people
set p_props to properties of source_p
set first name of p_props to "_Copy "
& (first name of p_props as string)
set target_p to make new person at end of people with properties p_props
save addressbook
end tell
but i get an error "CannotCreateScriptCommandError".
however, createing a new card with few props like {first name: "bob", last
name: "builder"} works.
The reason is
the p_props includes several read-only properties creation date,
modification date, id which you cannot set (especially id). So you
need to remove those. A few properties appear automatically (name, vcard) and
should be left out. Note that if you really plan to prefix "_Copy" or similar,
you first need to check whether the value is 'missing value' and don't do it
in that case. And don't try it with non-text types (date for birth date).
so what is the easiest way to duplicate a person
in the addressbook?
Extract
just the non-read-only props from the person. You need to do the same for all
the properties of all the elements of a person (address, phone, etc.)
too.
It's absurd that 'duplicate' which is in the Standard
Suite, doesn't work for person, not even 'duplicate person x to end of
persons' (which does compile). But it doesn't. So you have to do
this:
tell application "Address
Book" set source_p to person "Joe
Bloggs" tell source_p set p_props to its properties set allAddresses to properties of every address set allPhones to properties of every phone set alleMails to properties of every email set allRelatedPeople
to properties
of every
related
name set allCustomDates
to properties
of every
custom
date set {allAIMHandles,
allMSNHandles, allICQHandles, allJabberHandles, allYahooHandles} to
{properties of
every AIM Handle,
properties of
every MSN handle,
properties of
every ICQ handle,
properties of
every Jabber
handle, properties of every Yahoo
handle} set allGroups to every group end tell tell p_props set {maidenName, middleName, phoneticLastName,
ifOrganization, theDepartment, thesuffix,
theNote, lastName, phoneticFirstName, theCompany,
birthDate, theTitle,
jobTitle, theNickname,
phoneticMiddleName, theImage, firstName, homePage} to {maiden name, middle name,
phonetic last name, organization, department,
suffix, note, last name, phonetic first
name, company, birth
date, title, job
title, nickname, phonetic middle name, image,
first name, home
page} if firstName ≠ missing value then
set firstName
to "_Copy " & firstName -- do same for any altered
values set newProps to {maiden name:maidenName, middle name:middleName, phonetic last
name:phoneticLastName, organization:ifOrganization,
department:theDepartment, suffix:thesuffix, note:theNote, last name:lastName, phonetic first
name:phoneticFirstName, company:theCompany, birth date:birthDate, title:theTitle, job title:jobTitle, nickname:theNickname, phonetic middle name:phoneticMiddleName, image:theImage, first name:firstName, home page:homePage} end tell set target_p to make new person at end of people with properties newProps tell target_p repeat with
i from 1 to (count allAddresses) set addressProps to item i of allAddresses tell addressProps to set targetAddressProps to
{label:label, street:street, city:city, state:state, zip:zip, country:country, country code:country
code} make new address at end of addresses with properties
targetAddressProps end repeat repeat with
i from 1 to (count allPhones) set phoneProps to item i of allPhones tell phoneProps to set targetPhoneProps to
{label:label, value:value} make new phone at end of phones with properties targetPhoneProps end repeat repeat with
i from 1 to (count alleMails) set emailProps to item i of alleMails tell emailProps to set targetEmailProps to
{label:label, value:value} make new email at end of emails with properties targetEmailProps end repeat repeat with
i from 1 to (count allRelatedPeople) set relatedProps to item i of allRelatedPeople tell relatedProps to set targetRelatedProps to
{label:label, value:value} make new related name at end of related names with properties
targetRelatedProps end repeat repeat with
i from 1 to (count allCustomDates) set dateProps to item i of allCustomDates tell dateProps to set targetDateProps to
{label:label, value:value} make new custom date at end of custom dates with properties
targetDateProps end repeat repeat with
i from 1 to (count allAIMHandles) set aimProps to item i of allAIMHandles tell aimProps to set targetAimProps to
{label:label, value:value} make new AIM Handle at end of AIM handles with properties
targetAimProps end repeat repeat with
i from 1 to (count allMSNHandles) set msnProps to item i of allMSNHandles tell msnProps to set targetMsnProps to
{label:label, value:value} make new MSN handle at end of MSN handles with properties
targetMsnProps end repeat repeat with
i from 1 to (count allICQHandles) set icqProps to item i of allICQHandles tell icqProps to set targetIcqProps to
{label:label, value:value} make new ICQ handle at end of ICQ handles with properties
targetIcqProps end repeat repeat with
i from 1 to (count allJabberHandles) set jabberProps to item i of allJabberHandles tell jabberProps to set targetjabberProps to
{label:label, value:value} make new Jabber handle at end of Jabber handles with properties
targetjabberProps end repeat repeat with
i from 1 to (count allYahooHandles) set yahooProps to item i of allYahooHandles tell yahooProps to set targetYahooProps to
{label:label, value:value} make new Yahoo handle at end of Yahoo handles with properties
targetYahooProps end repeat end tell repeat with
i from 1 to (count allGroups) set theGroup to item i of allGroups add target_p to theGroup end repeat save addressbook end tell
-- Paul
Berkowitz
_______________________________________________ Do not post admin
requests to the list. They will be ignored. Applescript-users mailing
list
(email@hidden) Help/Unsubscribe/Update your
email sent to email@hidden
|