The EBMac Dictionary Viewer has a Service feature that works well, except for the built-in Preview application. So I made a simple snippet for looking up for in pdf files with Preview app, but has a minor problem.
If you run this script before/without launching the dictionary application, there is a problem that you cannot look for because the search field is not focused. However, as long as the application is up and running, there is no problem. You can search as expected.
It also may be a good idea to move your tell system events block to inside the tell Music block. This kinda ensures the keystroke are happening “towards” the music app.
After the activate is a good place to add the delay 0.5
This will ensure that the music app has been brought to the for front and gives a bit of time to settle before the keystrokes