I have created this AppleScript, which lives in my Scripts menu and takes a list of terms (single words or phrases) open on a TextEdit window (each on its own line), and uses UI Scripting to find the definitions for each term in Sherlock, and then paste them on a new document in TextEdit.
Since neither TextEdit or Sherlock is sufficiently scriptable for the task, UI scripting is necessary (Sherlock is less scriptable than TextEdit). Now, I was not able to pass clicks to Sherlock or obtain the contents of any field, but I was able to send it keystrokes and figure out the status of the fields (empty or selected). I move around using tabs until I find myself on the right field, and then I do a Command-A and Command-C (select all and then copy). The part that calls Sherlock is in its own procedure, so it can be used to retrieve definitions from Sherlock from any script. I am not happy with having to use the delay command as that makes the script potentially dependent on the speed of the machine.
A shell script would have been much quicker and I would be able to use the machine while it is running. However, the benefit of doing it this way is that the created TextEdit RTF preserves all the links that were present in Sherlock, and the formatting.
If, by mistake you run it on a TextEdit document that is not a list of words each on its own line, the script will try to define each line. That is why I have it saved as an application, which therefore can be forced to quit from the Dock.
Finally, I am curious if any of you knows of a way to insert text in a document using Applescript into an open window in TextEdit (without losing the formatting) that would avoid the constant going back and forth between Sherlock and TextEdit.
[robg adds: I tested this one on a 12" PowerBook, and it worked fine with the delay setting specified in the script. If you have a slower machine, you may need to change it...]
Since neither TextEdit or Sherlock is sufficiently scriptable for the task, UI scripting is necessary (Sherlock is less scriptable than TextEdit). Now, I was not able to pass clicks to Sherlock or obtain the contents of any field, but I was able to send it keystrokes and figure out the status of the fields (empty or selected). I move around using tabs until I find myself on the right field, and then I do a Command-A and Command-C (select all and then copy). The part that calls Sherlock is in its own procedure, so it can be used to retrieve definitions from Sherlock from any script. I am not happy with having to use the delay command as that makes the script potentially dependent on the speed of the machine.
A shell script would have been much quicker and I would be able to use the machine while it is running. However, the benefit of doing it this way is that the created TextEdit RTF preserves all the links that were present in Sherlock, and the formatting.
If, by mistake you run it on a TextEdit document that is not a list of words each on its own line, the script will try to define each line. That is why I have it saved as an application, which therefore can be forced to quit from the Dock.
Finally, I am curious if any of you knows of a way to insert text in a document using Applescript into an open window in TextEdit (without losing the formatting) that would avoid the constant going back and forth between Sherlock and TextEdit.
[robg adds: I tested this one on a 12" PowerBook, and it worked fine with the delay setting specified in the script. If you have a slower machine, you may need to change it...]
•
[4,803 views]

