Excel Applescript Question

Hey all, I’m a newbie when it comes to Applescript.

I’m trying to find a way to have excel cells autofill with a phone number and email address from Address Book when I type someone’s name in. I have an envelope widget that has this same feature, just wondering if it’s possible to duplicate it in Excel.

Thanks!

Hi,

Welcome to MacScripter’s. When you have a problem you need to solve it’s easiest if you break the problem down into parts. For you example I would think about these steps to solve the problem…

  1. how do I get input from a user ie. a person’s name
  2. knowing a person’s name, can I get their information from the address book?
  3. can I open a spreadsheet in excel
  4. can I find an open row in the spreadsheet?
  5. can I put the person’s information into the open row in the spreadsheet?

So let’s work on step 1. Applescript has the “display dialog” command when we want to show or get information. To get information we can do this…

set theResult to display dialog "Give me a person's last name." default answer ""
set lastName to text returned of theResult
set theResult to display dialog "Give me the person's first name." default answer ""
set firstName to text returned of theResult
return firstName & space & lastName

Now that you have the first and last name let’s work on step 2. We can ask the address book application for information about that person. For example let’s get the person’s birthday…

set theResult to display dialog "Give me a person's last name." default answer ""
set lastName to text returned of theResult
set theResult to display dialog "Give me the person's first name." default answer ""
set firstName to text returned of theResult

tell application "Address Book"
	set thePerson to first person whose first name is firstName and last name is lastName
	tell thePerson
		set theBirthday to birth date
	end tell
end tell

So as you can see, you can break the problem into small steps and make it easier to solve. Here’s your first 2 steps. Try to solve the next step. The first place to look for answers is in an application’s applescript dictionary. When in Applescript Editor, choose “open dictionary” under the file menu and select an application. The dictionary contains all the commands you can use with an application. You can also get help by searching on this website and of course you can ask questions too. Good luck.

What version of Excel are you using?
If you are using 2004 or 2011, you could write a UDF in VBA that looks into address book.