Addressbook Pages Applescript

I’m new to applescripting but giving it a real go as i really see the potential. I’m having two problems with the following script, 1 I would
like thePeopleList to be in alphabetical order, is it possible and Two I would like to get the “work” address but every time I try it it says my access is not granted. Please help. I know it’s probably basic but it would really help me.


tell application “Address Book”
set thePeopleList to name of every person --thePeopleList is a list --would like to have this in an alphabetical order
end tell
set thePersonChosen to (choose from list thePeopleList with prompt " Please choose a Person :")
tell application “Address Book”
set thePersonId to every person whose name is thePersonChosen as string
set thePersonFirstName to (first name of (item 1 of thePersonId)) as string
if thePersonFirstName is missing value then return “” as string
set thePersonLastName to (last name of (item 1 of thePersonId)) as string
if thePersonLastName is missing value then return “” as string
set thePersonFullName to (name of (item 1 of thePersonId)) as string
if thePersonFullName is missing value then return “” as string
set thePersonFormattedAddress to (value of address whose label is “work” of (item 1 of thePersonId)) as string
if thePersonFormattedAddress is missing value then return “” as string
set thePersonCompany to (organization of (item 1 of thePersonId)) as string
if thePersonCompany is missing value then return “”
end tell


Model: Imac,macbook,
Browser: Safari 531.22.7
Operating System: Mac OS X (10.6)

I’m sorry, but it buges me when people get BBCode wrong. You put the code INSIDE the tags.

tell application "Address Book"
        set thePeopleList to name of every person --thePeopleList is a list --would like to have this in an alphabetical order
    end tell
    set thePersonChosen to (choose from list thePeopleList with prompt " Please choose a Person :")
    tell application "Address Book"
        set thePersonId to every person whose name is thePersonChosen as string
        set thePersonFirstName to (first name of (item 1 of thePersonId)) as string
        if thePersonFirstName is missing value then return "" as string
        set thePersonLastName to (last name of (item 1 of thePersonId)) as string
        if thePersonLastName is missing value then return "" as string
        set thePersonFullName to (name of (item 1 of thePersonId)) as string
        if thePersonFullName is missing value then return "" as string
        set thePersonFormattedAddress to (value of address whose label is "work" of (item 1 of thePersonId)) as string
        if thePersonFormattedAddress is missing value then return "" as string
        set thePersonCompany to (organization of (item 1 of thePersonId)) as string
        if thePersonCompany is missing value then return ""
    end tell

Sorry first time for everything

I am newbie as well !

Found this on this site in answer to part 1-sort in alphabetical order - add in the other items

set Lst to {}
tell application "Address Book"
	set thePeopleList to every person
	repeat with i from 1 to count of thePeopleList
		set thename to (name of item i of thePeopleList)
		set the end of Lst to thename
	end repeat
end tell
set unsortedList to Lst
set old_delims to AppleScript's text item delimiters
set AppleScript's text item delimiters to {ASCII character 10}
set theList to paragraphs of (do shell script "echo " & quoted form of (unsortedList as string) & "| sort  -d -f")
set AppleScript's text item delimiters to old_delims
theList

Cheers,

Val

Thanks a lot. Any idea for getting the work address from address book anyone?

Try this. It might work but…

set theLabel to "work"
tell application "Address Book"
	repeat with i from 1 to (count of address of thePersonChosen)
		if theLabel = (label of address i of thePersonChosen) then
			set ADofPC to address i of thePersonChosen
		end if
	end repeat
end tell

Cheers,

Val

Hi,

try this


tell application "Address Book" to set thePeopleList to name of every person
set {TID, text item delimiters} to {text item delimiters, linefeed}
set theList to paragraphs of (do shell script "echo " & quoted form of (thePeopleList as text) & "| sort  -d -f")
set text item delimiters to TID
set thePersonChosen to (choose from list theList with prompt " Please choose a Person :")
if thePersonChosen is false then return

tell application "Address Book"
	set foundPerson to 1st person whose name is (item 1 of thePersonChosen)
	tell foundPerson
		set workAddress to 1st address whose label is "work"
	end tell
end tell

Thanks val I’ll try it
merci Stefan c’est gentil je pense qu’il marche finalement

if you have any sense don’t touch mine !
StephanK’s first language is Applescript!
Check out this Site.

Val

VAl

I’m quite good with langauges, but applescript’s stronger than me, for the moment. StefenK is suisse so he probably speaks about five. (…thumbing through yellow pages, "English lessons… French lessons… now where’s the applescript)