This script is an example of User Interface (UI) scripting available on Mac OSX v10.3 and above (see more info.)

This script automates the completion of the New Contact window in Daylite with data contained in a Microsoft Excel sheet (i.e. records located in rows.)

My problem to solve was getting a weekly supply of sales leads into DayLite without having to master F-Script, or the class types, Cocoa notation, etc. etc.


So I use Applescript to automate the entry as I contact the sales lead from Excel into DayLite. The code is straight forward and completely the example of how to be a lazy programmer/scripter, but it works and saves me time.

Use what you can...at least you get get an idea of UI scripting and a few tidbits of the Excel Applescript dictionary - John

Download the script here

(* This Applescript will populate the New Contact
window in DayLite with contact info on a single
line in Microsoft Excel. It will require mod-
ification to match your data, but is a good
start on integrating. Didn't feel like learning
F-script and no useful Daylite dictionary, so
just UI scripting to brute force the solution.
17-March-2007 jay_dub@mac.com *)


tell application "Daylite 3.2b1092" to activate

-- Daylite switch to Contacts
tell application "System Events"
tell process "Daylite 3.2b1092"
tell menu bar 1
tell menu bar item "View"
tell menu "View"
click menu item "Contacts"
end tell
end tell
end tell
end tell
end tell

-- New Contact
tell application "System Events"
tell process "Daylite 3.2b1092"
tell menu bar 1
tell menu bar item "Create"
tell menu "Create"
click menu item "New Contact"
end tell
end tell
end tell
end tell
end tell

-- Extract the data from the current line in Excel
tell application "Microsoft Excel"
Activate
set myRange to Selection -- You need to select the first cell on the beginning row
set thisRow to Row of ActiveCell
-- Get the Contact info
set thisContact to the Value of Range (("R" & thisRow as text) & "C2") -- second column is Contact whole name
set numWords to count of words of thisContact
set firstName to first word of thisContact
set lastName to words 2 thru numWords of thisContact --this will include any suffixes
set thisEmail to Value of Range (("R" & thisRow as text) & "C3") -- third column is email address
set Address1 to Value of Range (("R" & thisRow as text) & "C5") -- fifth column is address1
set Address2 to Value of Range (("R" & thisRow as text) & "C6") -- sixth column is address2
if Address2 is not equal to "" then
set thisAddress to Address1 & return & Address2
else
set thisAddress to Address1
end if
set thisCity to Value of Range (("R" & thisRow as text) & "C7") -- seventh column is city
set thisZip to Value of Range (("R" & thisRow as text) & "C8") -- eigth column is zip
set thisState to Value of Range (("R" & thisRow as text) & "C9") -- ninth column is state
set thisPhone to Value of Range (("R" & thisRow as text) & "C10") -- tenth column is phone
set thisInterest to Value of Range (("R" & thisRow as text) & "C12") -- twelfth column is interest
end tell

-- Fill in the information, the first field is Salutation
tell application "Daylite 3.2b1092" to activate
tell application "System Events"
keystroke tab -- skip Saluation
keystroke firstName as text
keystroke tab
keystroke tab
keystroke lastName as text
keystroke tab
keystroke tab
keystroke thisEmail as text
keystroke tab
keystroke thisPhone as text
keystroke tab
keystroke tab
keystroke thisAddress
keystroke tab
keystroke thisCity
keystroke tab
keystroke thisState
keystroke tab
keystroke "USA"
keystroke thisZip
end tell