-- Save the default Applescript delimiter set savedTextItemDelimiters to AppleScript's text item delimiters -- Set the Applescript delimiter to the Unix newline character set AppleScript's text item delimiters to {ASCII character 10} tell application "TextEdit" -- Get the list of terms to be processed (one per line) set my_text to the text of document 1 -- Create a window where to put the results make new document at beginning end tell -- Define each term repeat with i from 1 to count text items of my_text set my_term to text item i of my_text -- Only process non-empty lines if my_term is not "" then -- Place the Sherlock definition of "my_term" in the clipboard define(my_term) -- Activate TextEdit tell application "TextEdit" to activate tell application "System Events" tell application process "TextEdit" set frontmost to true -- Paste the clipboard and type a separator in TextEdit keystroke "v" using {command down} keystroke return keystroke return keystroke "----------------------------------------" keystroke return keystroke return end tell end tell end if end repeat -- Restore the default Applescript delimiter set AppleScript's text item delimiters to savedTextItemDelimiters -- Procedure to set the clipboard to a Sherlock Dictionary search on define(my_term) -- Clear the clipboard set the clipboard to "" -- Define in Sherlock "my_term" tell application "Sherlock" search Internet for  my_term as Unicode text in channel "Dictionary" with display activate activate end tell tell application "System Events" tell application process "Sherlock" -- Make sure Sherlock is in front set frontmost to true -- Wait for Sherlock to do the search repeat until  value of busy indicator 1 of group 1 of  window "Sherlock - Dictionary" is false end repeat delay 0.5 -- Check to see if Sherlock found anything -- Otherwise return an error message try get static text 1 of group 1 of UI element 1  of scroll area 2 of splitter group 1  of group 1 of window "Sherlock - Dictionary" on error set the clipboard to  "Could not find a definition for: " & my_term return end try -- Use repeated tabbing to focus on the definition repeat until  focused of scroll area 2 of splitter group 1  of group 1 of window "Sherlock - Dictionary" keystroke tab end repeat -- Select "All" the definition and then "Copy" keystroke "ac" using {command down} end tell end tell -- Wait until the changes to the clipboard take effect set cont to false repeat until cont delay 0.5 try get the clipboard set cont to true on error set cont to false beep end try end repeat return end define