I’d like to pass a string using PopClip to a python script. Is this possible, if yes, how?
Thanks!
I’d like to pass a string using PopClip to a python script. Is this possible, if yes, how?
Thanks!
Absolutely! You’ll need to create “full” extension rather than a snippet though. Thankfully it’s quite easy. Just create a folder and make text file called Config.yaml
in there — this is in the same format as snippets. Then add your python script. And name the folder with the extension .popclipext
. Something like this:
-- MyExt.popclipext
|
|-- Config.yaml
|-- myscript.py
Now your Config.yaml could be something like:
name: My Extension
shell script file: myscript.py
script interpreter: python3
Finally to install or update your extension into PopClip for testing, double click the MyExt.popclipext
folder in Finder.
For more details see https://github.com/pilotmoon/PopClip-Extensions#shell-script-actions
Thanks for making this clear. Might I ask how to access the selected text within the python script? I tried to derive it form the other examples, but failed.
The text will be in an environment variable called POPCLIP_TEXT
. I’m not a python programmer at all, and I haven’t verified this, but I think something like
text = os.environ[POPCLIP_TEXT]
ought to do it.
Other variables are available too, the full table is at: https://github.com/pilotmoon/PopClip-Extensions#script-fields
Thanks!
import os
text = os.environ['POPCLIP_TEXT']
is working fine.
That’s great. I’ve added a Python example to the docs — it’s probably the most popular scripting language, after all.