Default Postal Address & Applescript

A

Andy Whitaker

Hi,

I'm trying to retrieve the default postal address of a contact using
Applescript. The applescript I'm using is:

set thisDefaultPostal to name of default postal address of theContact

Where 'theContact' contains a list of contacts.

For some reason the command returns 28005 for home and 29291 for work postal
addresses. What is the significance of these numbers? I was expecting either
"Home", "Work" or "Other" as it states in the documentation.

By the way, I'm also extracting other information from 'theContact' which
works as expected.

Thanks for your help,

Andy
 
B

Barry Wainwright

Hi,

I'm trying to retrieve the default postal address of a contact using
Applescript. The applescript I'm using is:

set thisDefaultPostal to name of default postal address of theContact

Where 'theContact' contains a list of contacts.

For some reason the command returns 28005 for home and 29291 for work postal
addresses. What is the significance of these numbers? I was expecting either
"Home", "Work" or "Other" as it states in the documentation.

By the way, I'm also extracting other information from 'theContact' which
works as expected.

Thanks for your help,

Andy

The 'default postal address' of a contact returns a constant with the
value of 'home', 'work' or 'other'. Your script line is trying to
extract the 'name' property of that constant, but it doesn't have any
properties! This is bad enough on a single contact, but then you are
compounding the problem by asking for it on a list of contacts. The
script should have errored - it is a bug that it produces any value at
all!

From the context you supply, I am guessing that you want to extract the
contents of the postal address which is marked as the default for each
contact in the list. So you would like to do something like
[psuedocode]:
(note that this script will NOT work)

set addressList to postal address which is default postal address of
contactList

Unfortunately, there is no direct way to coerce a constant to an
appleScript keyword, which is effectively what you are trying to do. A
contact class has two postal address properties called 'home address'
and 'business address'. Which of these is the default is made clear(?)
by the 'default postal address' property which can have a value of
'home' (maps to home address), 'work' (maps the 'business address' or
'other'† (maps to nothing in particular and cannot be set to this value
through the UI, although you can set this ambiguous value through
appleScript). The contents of the default postal address property are a
constant which cannot be coerced to any other value.

What you need to do is loop through your contact list extracting the
relevant address based on the value of the 'default postal address'
property. something like this:

set listOfAddresses to {}
repeat with aContact in listOfContacts
if default postal address aContact is home then -- note value is not quoted!
copy home address of aContact to end of listOfAddresses
else
copy business address of aContact to end of listOfAddresses
end if
end repeat

Unfortunately, there is no way to do this without looping through each
contact in the list.


† the reason for the 'other' value in this case is that the list of
values is re-used from the 'email address type' label, which can be
marked 'home', 'work' or 'other'.
 
A

Andy Whitaker

Thanks for the reply,

After I posted my question I trid various options and the following returns
the right information for me ('home' or 'work'):

try
set thisDefaultPostal to default postal address of theContact as
string
on error
set thisDefaultPostal to "other"
end try

Now if only I can work out how to delete a contact using applescript....

Cheers,

Andy

Hi,

I'm trying to retrieve the default postal address of a contact using
Applescript. The applescript I'm using is:

set thisDefaultPostal to name of default postal address of theContact

Where 'theContact' contains a list of contacts.

For some reason the command returns 28005 for home and 29291 for work postal
addresses. What is the significance of these numbers? I was expecting either
"Home", "Work" or "Other" as it states in the documentation.

By the way, I'm also extracting other information from 'theContact' which
works as expected.

Thanks for your help,

Andy

The 'default postal address' of a contact returns a constant with the
value of 'home', 'work' or 'other'. Your script line is trying to
extract the 'name' property of that constant, but it doesn't have any
properties! This is bad enough on a single contact, but then you are
compounding the problem by asking for it on a list of contacts. The
script should have errored - it is a bug that it produces any value at
all!

From the context you supply, I am guessing that you want to extract the
contents of the postal address which is marked as the default for each
contact in the list. So you would like to do something like
[psuedocode]:
(note that this script will NOT work)

set addressList to postal address which is default postal address of
contactList

Unfortunately, there is no direct way to coerce a constant to an
appleScript keyword, which is effectively what you are trying to do. A
contact class has two postal address properties called 'home address'
and 'business address'. Which of these is the default is made clear(?)
by the 'default postal address' property which can have a value of
'home' (maps to home address), 'work' (maps the 'business address' or
'other'† (maps to nothing in particular and cannot be set to this value
through the UI, although you can set this ambiguous value through
appleScript). The contents of the default postal address property are a
constant which cannot be coerced to any other value.

What you need to do is loop through your contact list extracting the
relevant address based on the value of the 'default postal address'
property. something like this:

set listOfAddresses to {}
repeat with aContact in listOfContacts
if default postal address aContact is home then -- note value is not quoted!
copy home address of aContact to end of listOfAddresses
else
copy business address of aContact to end of listOfAddresses
end if
end repeat

Unfortunately, there is no way to do this without looping through each
contact in the list.


† the reason for the 'other' value in this case is that the list of
values is re-used from the 'email address type' label, which can be
marked 'home', 'work' or 'other'.
 
B

Barry Wainwright

Thanks for the reply,
...
Now if only I can work out how to delete a contact using applescript....

Cheers,

Andy

delete aContact

should work.


--
Barry Wainwright
Microsoft MVP
(see http://mvp.support.microsoft.com for more information)
Like most MVPs, I am responding to your query through the public
newsgroup channel (NNTP). Microsoft is planning to close the public
newsgroups which would effectively disable this channel and may affect
the number of answers that are given. Please post any concerns you have
about these plans in this newsgroup so we can forward them on to
Microsoft.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top