Skip to content

Instantly share code, notes, and snippets.

@phillco
Created August 15, 2024 00:36
Show Gist options
  • Save phillco/4b52e50afc714e70511b1484afc92e59 to your computer and use it in GitHub Desktop.
Save phillco/4b52e50afc714e70511b1484afc92e59 to your computer and use it in GitHub Desktop.
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"
)
if len(handoff_items) == 0:
actions.app.notify("No handoff available")
return
for item in handoff_items:
app_name = item.get("AXTitle")
source_label = item.get("AXStatusLabel")
if source_label:
# handoff-badge-...
source_to_emoji = {
"iphoneX": "📱",
"mac": "💻",
}
source = source_label.split("-")[-1]
emoji = source_to_emoji.get(source, "")
actions.app.notify(f"Accepting handoff from {emoji}: {app_name}")
item.perform("AXPress")
^[dock] handoff (accept | open): user.dock_handoff_accept()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment