Run Python Script Which Needs Some Text and Additional Commands as Input

Hello!

This is a bit too much for my technical skill ) If somebody can help it would be very nice.

I have this script GitHub - OpenPecha/pyewts: Tibetan Unicode to Wylie converter. (EWTS-Extended Wylie Transliteration Scheme) which as you can see needs some input from user to specify conversion.

Currently, I half-automated it by pasting in IDLE shell word wrapped into the needed command, but I understand that it is kind of strange way of doing it.

How can I just pass a word from the clipboard directly to this script and specify command?

In my case mostly print(converter.toWylie("wrapped_word")) Not running IDLE separately.

Also, when I run IDLE first time after closing it I have to run these two commands in order for this script to work:

import pyewts
converter = pyewts.pyewts()

Hey @Gyaltsen,

It's best for everyone if you can post the simplest possible test-case macro that demonstrates your issue.

Making it easy for people to download, import, and test your work greatly improves the likelihood that you'll get timely and useful assistance.

Making people jump through hoops to figure out what you're doing is certain to decrease the likelihood that you'll get any help at all.

This is probably the easiest method of getting KM variables into Python 3.x:

#!/usr/bin/env python
import os
print(os.environ['KMVAR_local_Clipboard'])

If I remember correctly Python 2.x used this syntax:

#!/usr/bin/env python
import os
print os.environ['KMVAR_local_Clipboard']

Download: Python 3.x – Get Variable From Keyboard Maestro v1.0.kmmacros (2.2 KB)

Macro-Image

Keyboard Maestro Export

Macro-Notes
  • Macros are always disabled when imported into the Keyboard Maestro Editor.
    • The user must ensure the macro is enabled.
    • The user must also ensure the macro's parent macro-group is enabled.

System Information
  • macOS 10.14.6
  • Keyboard Maestro v10.2

Take Care,
Chris

(Keyboard Maestro Moderator)

1 Like

Works here only as:

#!/usr/bin/env python3 
import os
print(os.environ['KMVAR_local_Clipboard'])
1 Like

Ah.

I have my Python 3 install aliased to Python, so I never have to think about Python 2.7x unless I want to.

What do you get when you run this?

/usr/bin/python --version

usr/bin/python --version                                                                                
no such file or directory: usr/bin/python
which python                                                                                              
python: aliased to python3
which python3                                                                                              
/usr/local/bin/python3
/usr/local/bin/python3 --version                                                                            
Python 3.10.9
1 Like

What version of macOS are you using?

I'm still stuck with Mojave...

Same here, latest Mojave version.

Then you definitely have Python 2 installed.

Oh, you ran this (missing the leading slash):

usr/bin/python --version

You should have run this:

/usr/bin/python --version