Created
August 15, 2024 00:36
-
-
Save phillco/4b52e50afc714e70511b1484afc92e59 to your computer and use it in GitHub Desktop.
Activate a handoff application in the dock with Talon
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
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") |
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
^[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