tools / home-automation / roku-type.py
home-automation/roku-type.py
Type free text into a Roku device's currently focused on-screen keyboard field (e.g. a search box) over its ECP API -- sends one keypress/Lit_<char> per character in a single call, instead of one fraglet run per letter. Pairs with home-automation/roku-press.py to navigate to the field first.
Use when the user asks to type a search query or other text into whatever on-screen text field is currently focused on a Roku.
- the file
- home-automation/roku-type.py
- its skill
- home-automation/SKILL.md (the whole home-automation pack)
- as knowledge
- okf/home-automation/roku-type.md
- on GitHub
- home-automation/roku-type.py ↗
Run it
1. Once per machine: install fragletc (Docker must already be running).
curl -fsSL https://raw.githubusercontent.com/ofthemachine/fraglet/main/install.sh | sh
2. Fetch the tool and print its contract.
curl -fsSLO https://tools.ofthemachine.com/home-automation/roku-type.py && chmod +x roku-type.py && ./roku-type.py --fraglet-help
3. Run it.
./roku-type.py -p ip="<ip>" -p text="<text>"
Parameters
| name | type | requirement | description |
|---|---|---|---|
| ip | string | required | LAN IP address of the Roku, e.g. 192.168.0.73 |
| text | string | required | Text to type into the currently focused on-screen field, e.g. "stargate atlantis" |
Outputs
stdout
Provenance
- image
- ofthemachine/python3@sha256:a015b4f9f0e7c1648f8fcd4164f6a296dd3c9189404f88f333a9764d08d13522
- reach
network=required— output depends on live external state; do not cache indefinitely.- procedure_hash
- sha256:ab21dcf066f0c8ecbadabf42918ee754c373ad7b54c43efacf11733c9ab4df48
- receipt
- add
--receipt run.jsonto any run;receipt/attest.pyverifies it against this hash without re-running.
Source
roku-type.py · 35 lines · sha256 ab21dcf066f0…
#!/usr/bin/env -S fragletc --image ofthemachine/python3@sha256:a015b4f9f0e7c1648f8fcd4164f6a296dd3c9189404f88f333a9764d08d13522
#: d=Type free text into a Roku device's currently focused on-screen keyboard field (e.g. a search box) over its ECP API -- sends one keypress/Lit_<char> per character in a single call, instead of one fraglet run per letter. Pairs with home-automation/roku-press.py to navigate to the field first.
#: when=Use when the user asks to type a search query or other text into whatever on-screen text field is currently focused on a Roku.
#: network=required
#: stdin=none
#: param=ip:required:d=LAN IP address of the Roku, e.g. 192.168.0.73
#: param=text:required:kind=text:d=Text to type into the currently focused on-screen field, e.g. "stargate atlantis"
import os
import sys
import time
import urllib.error
import urllib.parse
import urllib.request
ip = os.environ["IP"]
text = os.environ["TEXT"]
if not text:
print("text param is empty", file=sys.stderr)
sys.exit(1)
for i, ch in enumerate(text):
key = f"Lit_{ch}"
url = f"http://{ip}:8060/keypress/{urllib.parse.quote(key)}"
req = urllib.request.Request(url, method="POST")
try:
with urllib.request.urlopen(req, timeout=10):
pass
except urllib.error.URLError as e:
print(f"roku type failed at character {i + 1}/{len(text)} ('{ch}'): {e}", file=sys.stderr)
sys.exit(1)
if i < len(text) - 1:
time.sleep(0.15)
print(f"OK: typed {len(text)} characters to {ip}")