On MacOS I'm using the Raycast application launcher which lets you write command scripts to be executed from the raycast menu or a shortcut key.
I wrote a short python script to send simple keyboard output using the pynput module. It worked as expected when I ran it manually from my command line but then I pasted it into a new Raycast command script:
#!/usr/bin/env python3
# Required parameters:
# @raycast.schemaVersion 1
# @raycast.title Text macro
# @raycast.mode compact
# Documentation:
# @raycast.description Write some text for me
from pynput.keyboard import Key
from pynput.keyboard import Controller as KeyboardController
import time
keyboard_controller = KeyboardController()
keyboard_controller.type("Hello world")
# script exits before all the keyboard output is sent so I had to put a sleep here
time.sleep(3)
When I execute the script from Raycast, it throws an error:
Reason: Traceback (most recent call last):
File "/Users/myusername/Projects/raycast-commands/aws-tags.py", line 14, in <module>
from pynput.keyboard import Key
ModuleNotFoundError: No module named 'pynput'
Domain: scripts
Time: 13:56:07.272
Either I need to install pynput in a different way or I am not importing it correctly for the Raycast script.
I fixed this by running:
python3 -m pip install pynput