Skip to content

Instantly share code, notes, and snippets.

View phillco's full-sized avatar

Phil Cohen phillco

View GitHub Profile
@phillco
phillco / pyast.py
Created February 22, 2022 07:00
Parsing/navigating through the Python AST with talon
import ast
import os.path
from talon import Context, Module, actions, ui
ctx = Context()
mod = Module()
# Stores the original AST elements so we can refer to specific properties of them
REFERENCE = {}
@phillco
phillco / focus.py
Last active August 22, 2023 01:00
Focusing window grammar
from talon import Context, Module, actions, app, ui
ctx = Context()
mod = Module()
mod.list("window_titles", desc="All window titles")
APPLICATION_MATCH_REGEX = re.compile("PyCharm|IntelliJ.*|TextEdit")
@phillco
phillco / electron_accessibility.py
Created August 9, 2023 22:22
Enable accessibility on electron apps in macOS
from talon import ui
from talon.mac.ui import App
from talon.ui import UIErr
APPS = [
"Slack",
"Google Chrome",
]
import ollama
from talon.types import Span
OLLAMA_MODEL = "gemma2:2b"
def process_text(text, template):
print(f"Sending text to model: {text[:50]}...")
prompt = template.replace("$text", text)
try:
@phillco
phillco / handoff.py
Created August 15, 2024 00:36
Activate a handoff application in the dock with Talon
from talon import Module, actions, ui
mod = Module()
@mod.action_class
class Actions:
def dock_handoff_accept():
"""Accept a Handoff from another device via the dock"""
handoff_items = ui.apps(bundle="com.apple.dock")[0].element.children.find(
AXRole="AXDockItem", AXSubrole="AXHandoffDockItem"