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

Script Sherlock and TextEdit to batch-define terms Apps
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...]
    •    
  • Currently 2.50 / 5
  You rated: 2 / 5 (4 votes cast)
 
[4,803 views]  

Script Sherlock and TextEdit to batch-define terms | 2 comments | Create New Account
Click here to return to the 'Script Sherlock and TextEdit to batch-define terms' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Script Sherlock and TextEdit to batch-define terms
Authored by: ob1cannoli on Oct 15, '04 03:12:30PM

although i have not looked at your script, if you do:

tell application "APPNAME" to _____

it does not need to activate that application....although I'm unsure if if this also works for UI scripting.



[ Reply to This | # ]
Script Sherlock and TextEdit to batch-define terms
Authored by: ramonf on Oct 15, '04 08:40:38PM

You do need to activate an application (to bring it to the front) to use UI scripting :(



[ Reply to This | # ]