The following Automator script is supposed to open a Chrome tab and look up a Chinese word.
The service opens the Chrome tab when Latin characters are chosen, but mysteriously fails to open a tab when Chinese characters are chosen.
Works
- Open https://en.wikipedia.org/wiki/List_of_Chinese_classifiers.
- Highlight Latin character.
- Run service.
Fails
- Open https://en.wikipedia.org/wiki/List_of_Chinese_classifiers.
- Highlight Chinese character.
- Run service.
Run JavaScript
function run(input, parameters) {
var trimmedInput = input[0].replace(/\s/g, '');
return trimmedInput
}
Run AppleScript
on run {input, parameters}
return "http://www.cantonese.sheik.co.uk/dictionary/search/?searchtype=2&text=" & input
end run
Run AppleScript
on run {input, parameters}
tell application "Google Chrome"
set curTabIndex to active tab index of front window
open location input
set active tab index of first window to curTabIndex
end tell
end run
Best Answer
The following example AppleScript code combines the three Automator actions shown in your OP into one Run AppleScript action.
Selecting the first Chinese character, from the link in your OP, and running the Automator Service/Quick Action it worked for me by opening a new tab to the target URL.
AppleScript's text item delimiters
to do the same thing as:.replace(/\s/g, '')
Note: The example AppleScript code is just that and does not contain any error handling as may be appropriate. The onus is upon the user to add any error handling as may be appropriate, needed or wanted.