I was trying to convert Chinese characters to Pinyin with a package developed by JavaScript.
And this is the solution in the yaml block:
# popclip Pinyin
name: Pinyin
title: Chinese Pinyin
icon: square 拼
applescript: do shell script "/opt/homebrew/bin/pinyin -s NORMAL -S -g {popclip text}"
after: paste-result
I can confirm that the shell command pinyin -s NORMAL -S -g [some Chinese characters] worked well in the Terminal. However, after the installation of the yaml block above, the extension did not work.
So I also created an extension with a shell file, an icon and Config.plist. And the shell script is:
#!/bin/zsh
/opt/homebrew/bin/pinyin -s NORMAL -S -g $POPCLIP_TEXT
Fortunately, It worked as expected.
So my question is why the extension invoked by AppleScript did not work, while the shell script worked? Thanks in advance!
Hey, I’m just looking into it, can you tell me what homebrew command I can use to install that tool. Is it libpinyin?:
I tried:
> brew install pinyin
Warning: No available formula with the name "pinyin".
==> **Searching for similarly named formulae...**
This similarly named formula was found:
libpinyin
To install it, run:
brew install libpinyin
The reason is that there is no return value from the AppleScript. You need to add return, like this:
applescript: return do shell script "..."
By the way, if you option(⌥)-click the popclip menu bar, you’ll see a debug window that gives some clues as to the problem when things go wrong (I would like to improve the debug output but it is a start).
Thanks. Strange, it works on mine. The error seems to be coming from the shell script running within the applescript. It seems an env command is not finding your node. Something different between our machines about the way the user path is set up in environment variables, perhaps.
Hey @tomben, I just wanted to let you know about an improvement in PopClip 2022.12. You can now put a shell script directly in a snippet without having to wrap it in an AppleScript anymore.
Like this:
# popclip Pinyin
name: Pinyin
title: Chinese Pinyin
icon: square 拼
after: paste-result
shell script: /opt/homebrew/bin/pinyin -s NORMAL -S -g "$POPCLIP_TEXT"
interpreter: zsh # note that an interpreter must be specified
Also, there is a new snippet header concept. So you can do it this way now: