• 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
vcard in Addressbook
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

vcard in Addressbook


  • Subject: vcard in Addressbook
  • From: "Sutapalli Satyanarayana" <email@hidden>
  • Date: Fri, 20 Mar 2009 00:55:24 -0600

I wrote small apple script to set the images for the entries in my address book depending on firstname, lastname and middle name.

So, for that I am iterating through all the entries of address book and setting the image.

Now, while iterating I am facing issue if the entry is a vcard. So, can some body tell me how to skip if the entry is a vcard. If I can find whether entry in addressbook is vcard, I want to just skip it.

Here is my script:


tell application "Address Book"

set the_file to (((path to desktop) as string) & "addbook.txt") as file specification

try --TRY1

open for access the_file with write permission  --Debug information to write

set eof of the_file to 0  --Clear old data

set the_people to every person -- Get the list of people from address book

set imagePath to POSIX path of (choose folder with prompt "Select an image folder:") --Get the image folder path

repeat with this_person in the_people --Repeat the same operation with every person in addressbook

                                                      --Check here for vcard or not

if (not (exists image of this_person)) then --check if image exists or not. if not exist proceed else skip

set fileName to missing value

                                                                        (*compute the file name from firstname, middlename and lastname + jpg *)

if (first name of this_person exists) and (middle name of this_person exists) and (last name of this_person exists) then

set fileName to imagePath & first name of this_person & " " & middle name of this_person & " " & last name of this_person & ".jpg"

set msg to "no"

tell application "Finder" to if exists fileName as POSIX file then set msg to "yes"  --check if image file exists or not

if msg = "yes" then

set idata to missing value

try -- TRY2

                                                                                                             (* set the image by reading the file *)

set fileOpen to open for access (fileName as POSIX file)

set idata to read fileOpen as TIFF picture

close access fileOpen

set image of this_person to idata

write (fileName & " Added") to the_file starting at eof

write return to the_file starting at eof

save addressbook

on error errs number errn

set errorTo to fileName & " Failed to set the image"

write (errorTo) to the_file starting at eof

write return to the_file starting at eof

try

close access fileOpen

end try

end try

else

set fileNotFound to fileName & " file not found."

write (fileNotFound) to the_file starting at eof

write return to the_file starting at eof

end if

end if

end if

end repeat

close access the_file

on error

write ("Couldn't put image") to the_file starting at eof

write return to the_file starting at eof

try

close access the_file

end try

end try

display dialog "Please check the log file addbook.txt on your desktop for more details"

end tell

 _______________________________________________
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

References: 
 >Re: Get List of window PC's in the network (From: "Knight, William H. (NIH/OD) [C]" <email@hidden>)
 >Re: Get List of window PC's in the network (From: Roger Howard <email@hidden>)
 >Re: Get List of window PC's in the network (From: Roger Howard <email@hidden>)
 >Applescript to set image in Addressbook (From: "Sutapalli Satyanarayana" <email@hidden>)
 >Re: Applescript to set image in Addressbook (From: "email@hidden" <email@hidden>)
 >Re: Applescript to set image in Addressbook (From: "Sutapalli Satyanarayana" <email@hidden>)

  • Prev by Date: Re: timeout block question (Axel Luttgens) (Jim Brandt)
  • Next by Date: which window
  • Previous by thread: Re: Applescript to set image in Addressbook
  • Next by thread: Re: Applescript to set image in Addressbook
  • Index(es):
    • Date
    • Thread