Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

A script to add pictures to Address Book Apps

I was looking for a way to automatically add pictures to my Address Book, and have discovered some possibly useful bits of information. As with all empirical observations, your results may vary.

Apparently, Address Book (3.0.3) doesn't include picture information directly in its data files, nor are images directly accessible via AppleScript. Rather, it just puts any images you give it in ~/Library/Application Support/AddressBook/Images/, but with a cryptic name and format. The name of the image files seem to be based on the IDs that Address Book uses internally. You can access such IDs with AppleScript, eg, this script:

% osascript -e 'tell application "Address Book" to get id of person 1'

returns '15E7B9BC-C142-11D6-9F6E-0002979E861C:ABPerson' for me. The name that Address Book uses for an image file seems to be the ID of that person with the ':ABPerson' suffix stripped. I wasn't able to penetrate the image format that Apple uses by default, but jpg's (moved and renamed as just described - without a '.jpg' suffix) seem to display in Address Book just fine.

Using this information, one can take a folder full of "email@address.com.jpg" files, and automatically add those images to the people in a given group with those email addresses. Here's my successful if inelegant version:

tell application "Address Book"
  set the_people to every person in group "Work"
  set home to (do shell script "echo ~")
  set destination_dir to home & "/Library/Application Support/AddressBook/Images/"
  set image_dir to POSIX path of (choose folder with prompt "Choose an image directory:")
    
  repeat with this_person in the_people
    if email of this_person exists then
      set old_file to ((value of email 1 of this_person) as text) & ".jpg"
      set old_path to quoted form of (image_dir & old_file)
      set new_file to characters 1 through -10 of (id of this_person as text) as text
      set new_path to quoted form of (destination_dir & new_file)
      set my_command to "cp " & old_path & " " & new_path
      try
        do shell script my_command
      end try
    end if
  end repeat
end tell

Now if I could only figure out how to get Mail.app to show these pictures...

[robg adds: I have not tested this one...]

    •    
  • Currently 1.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (2 votes cast)
 
[16,995 views]  

A script to add pictures to Address Book | 7 comments | Create New Account
Click here to return to the 'A script to add pictures to Address Book' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
A script to add pictures to Address Book
Authored by: dr_turgeon on Mar 07, '03 09:59:09AM

>wasn't able to penetrate the image format Apple uses by default

I opened a file from the Address Book images folder (into TextEdit)
and saw the first two characters being "MM". And I've been able to
add a tiff suffix to these files in the past and have Preview open
them. It worked.



[ Reply to This | # ]
SenderPix
Authored by: nturpin on Mar 07, '03 10:15:11AM

There is a program called SenderPix that will let mail display photos from
your Address Book

http://homepage.mac.com/jacken/senderpix/FileSharing6.html



[ Reply to This | # ]
SenderPix
Authored by: nturpin on Mar 07, '03 11:15:51AM

There is a program called SenderPix that will let mail display photos from
your Address Book

http://homepage.mac.com/jacken/senderpix/FileSharing6.html



[ Reply to This | # ]
A script to add pictures to Address Book
Authored by: patsdave on Mar 07, '03 11:21:01AM

I am trying to figure out how to use Applescript in Mail.app to transfer a message based on someone in my address book to two mailboxes AND open one of them upon arrival.

Please help!!!!

NOTE: If you use the program listed in a comment above (senderpix) it does show the photo in Mail.app.



[ Reply to This | # ]
A script to add pictures to Address Book
Authored by: dubmaster on Mar 07, '03 12:18:03PM

actually, the pictures for the addressbook and the email are stored in an folder, in the Library, either /Library or ~user/Library.

create a folder named: Images in one of those Libraries and in it create a folder : People.
any image in a tiff format with the email address of the person will be schown in your email AND the addressboock.
if they are the same. Example: a picture named user@mac.com.tiff would be visible in the addressbiik under the user who's email (any of his email) is listed as user@mac.com.
any message received from user@mac.com would show this immage as well.

---
DubMaster
--
Rehab is for quitters!



[ Reply to This | # ]
Just use ~/Library/Images/People/
Authored by: Moofisto on Mar 07, '03 10:36:39PM

Yes, as dubmaster said, you can just put your pics of people here.

Format: uncompressed or LZW-compressed 8-bit TIFF
Filename: yourfriends@email.address.com.tiff (just add .tiff, not .tif, to the email address)

Mail.app and Address Book pick these up. This is the old school 10.1 method that still works, fortunately.

128x128 pixel tiffs work best for me. They show up nicely in Mail.app (resized to 64x64), and reasonably well in Address Book (to 48x48). If you're really anal about a particular image in the Address Book, you can still add a 48x48 custom image by using the Address Book picture-adding function, which goes to the cryptic ~/Library/Application\ Support/AddressBook/Images/ directory of TIFFs. A custom image will then be preferred by Address Book over the image you have in ~/Library/Images/People/.

Also, have a look at MailPictures, a Mail.app add-on which lets Mail.app automatically trade the Mail/AddressBook pics of users when they mail each other. MailPictures uses the newer, more cryptic 10.2 AddressBook/Images method.



[ Reply to This | # ]
Just use ~/Library/Images/People/
Authored by: Tim Golden on Mar 11, '03 10:17:29PM

Bingo! Best thing since sliced bread.



[ Reply to This | # ]