Request: lookup words

I want to look up a selected word in pdf files using a third-party dictionary app.

Below is my scenario.

  1. Select a word in pdf file(copy)
  2. Launch the dictionary app
  3. Search(paste the word into the dictionary app and press Enter key)

Can I automate this flow with just one click in Popclip?

It would be greatly appreciated if someone could make this Snippet.

1 Like

Quite possibly. We would need to know which dictionary app it is though.

1 Like

Hi, Nick
Thank you for your quick and positive response. The app I want to use is a dictionary viewer called EBMac. It’s an application from Japan. The site is also in Japanese. Sorry for this.

http://ebstudio.info/manual/EBMac/
http://ebstudio.info/manual/EBMac/00about.php

Thank you.

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.

#popclip 
name: EBMac
icon: circle filled EB
before: copy
applescript: |
  tell application "EBMac" to Activate
  tell application "System Events"
  key code 55 & 0
  key code 55 & 9
  key code 36
  end tell

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.

Nice Job. I didn’t download the app because the download page had so many ads and fake butttons, I got freaked out about the app. I edited you post to turn the snippet into code block with ```

You might be interested in the Music source code which demonstrate one technique for waiting for focus:
https://github.com/pilotmoon/PopClip-Extensions/blob/master/source/Music.popclipext/musicsearch.applescript

I’m sorry to hear that there are many ads on that website. Sorry for the inconvenience.
I solved the problem by slightly modifying the script.

#popclip 
name: EBMac
icon: circle filled EB
before: copy
applescript: |
  tell application "EBMac"
     launch
     activate
  end tell
  tell application "System Events"
  key code 55 & 0
  key code 55 & 9
  key code 36
  end tell

Any further advice or help would be appreciated.
Thank you.

I’ve found sometimes with AppleScript and executing keycodes / keypresses you may need to introduce slight delay calls. Like before any keystrokes I’ve do a
delay 0.5

1 Like

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

2 Likes

Thank you for your advice, technomorph.

1 Like