Last active
June 9, 2025 05:31
-
-
Save Hamatti/9eda7cb7eeaacea7d76125ee6dfc69be to your computer and use it in GitHub Desktop.
A script that runs Playwright to open my Epson projector's web ui and clicks power button to start my projector.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env -S uv run --quiet --script | |
# requires installation of Playwright browsers before this script is run | |
# can be done with `pipx run playwright install` | |
# /// script | |
# requires-python = ">=3.12" | |
# dependencies = [ | |
# "python-dotenv", | |
# "playwright", | |
# ] | |
# /// | |
from playwright.sync_api import sync_playwright | |
from dotenv import dotenv_values | |
import os | |
creds = dotenv_values(f"{os.environ.get('HOME')}/.config/.epson-creds") | |
assert creds.get("EPSON_USERNAME") is not None, ( | |
"You must define EPSON_USERNAME in $HOME/.config/.epson-creds" | |
) | |
assert creds.get("EPSON_PASSWORD") is not None, ( | |
"You must define EPSON_PASSWORD in $HOME/.config/.epson-creds" | |
) | |
with sync_playwright() as p: | |
browser = p.firefox.launch() | |
# The projector's web UI uses basic auth | |
context = browser.new_context( | |
http_credentials={ | |
"username": creds.get("EPSON_USERNAME"), | |
"password": creds.get("EPSON_PASSWORD"), | |
} | |
) | |
page = context.new_page() | |
# epson.local is my /etc/hosts alias for the actual projector IP | |
page.goto("http://epson.local/") | |
page.locator(".basic-control").click() | |
page.locator(".power").click() | |
browser.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment