The FooDoo Lounge

Palm Desktop

A few routines that should work1 in all versions, including Claris Organizer 2. See this page for more info on scripting PD2.x-4.0, or download a compiled script tutorial which contains versions of these handlers.

[1] The termonology changes in PD 2.6 mean that these will not compile directly under earlier versions. The only thing that needs changing is the term address n, which needs to be contact n to compile under V2.5.x and earlier.

Get a formatted name, company and address

Gets data from an address window and formats it so it can be used in letters or on envelopes. Uses the primary address unless empty, in which case it uses the secondary. Designed to be robust and fast, which is why there's so much of it. The second version is for PD4.1 and is one example of how the improved AS support has made life eaiser for scripters.

-- mailLabel -- by Richard Morton 1998-2002 --
-- Return a formatted name & address from an address/contact window in PD2.x-4.0
-- Pass an integer - the number of the address window (0 for the one on screen)
on mailLabel from n
    tell application "Palm Desktop" to ¬
        tell address n
            set fullName to full informal name
            set compName to company
            set fullAddress to mailing label of primary address
        end tell
    set noData to "<no name or company found>"
    set nameNComp to noData
    if fullName ≠ "" then set nameNComp to fullName
    if compName ≠ "" then -- get the company name if there is one
        if nameNComp noData then
            set nameNComp to nameNComp & return & compName
        else
            set nameNComp to compName
        end if
    end if
    set olTids to AppleScript's text item delimiters
    set AppleScript's text item delimiters to ":"
    try
        set nameAddress to (nameNComp & (text item 2 of fullAddress))
    on error -- Address1 is empty
        tell application "Palm Desktop" to set ¬
            fullAddress to mailing label of secondary address of address n
        try
            set nameAddress to (nameNComp & (text item 2 of fullAddress))
        on error -- Address2 is empty, give up
            set nameAddress to nameNComp & return & "<no address found>" & return
        end try
    end try
    set AppleScript's text item delimiters to olTids
    return nameAddress
end mailLabel

-- mailLabel -- by Richard Morton 1998-2003 --
-- Return a formatted name & address from an address window in PD4.1 or later
-- Pass an integer - the number of the address window (0 for the one on screen)
on mailLabel from n
    tell application "Palm Desktop" to tell address n
        set fullName to full informal name
        set companyName to company
        set fullAddress to formatted address of address one
    end tell
    set nameAndCompany to "" -- get a name &/or company name
    if fullName ≠ "" then set nameAndCompany to fullName & return
    if companyName ≠ "" then set nameAndCompany to nameAndCompany & companyName & return
    if nameAndCompany = "" then set nameAndCompany to "<no name or company found>" & return
    if fullAddress ≠ "" then -- use the primary address if there is one
        return nameAndCompany & fullAddress
    else -- try secondary address
        tell application "Palm Desktop" to tell thisRec to set fullAddress to formatted address of address two
        if fullAddress ≠ "" then
            return nameAndCompany & fullAddress
        else -- no address
            return nameAndCompany & "<no address found>"
        end if
    end if
end mailLabel

Get a contact's name & email address

-- getEmailData -- by Richard Morton 1998-2002 --
-- Return a list contining first name, last name & email address from a PD address window
-- Pass an integer - the number of the address window (0 for the one on screen)
on getEmailData from n
    tell application "Palm Desktop" to tell address n to ¬
        return {first name, last name, field text of custom 1} -- assumes default settings
end getEmailData

 

The FooDoo Lounge is Copyright © Richard Morton 2002-2005

|| url: http://www.foodoo.sunreal.com.au/code/pd_handlers.html
|| created: 4-Aug-03, 10:11 PM; updated: 4-Aug-03, 11:55 AM
|| size: 33295 bytes