Last active
November 11, 2024 11:01
-
-
Save grafuls/0883e840181fdc821d6ba817b3fe9c65 to your computer and use it in GitHub Desktop.
Finds and brings to front a google meet tab on brave browser
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/brave-browser-stable %U --remote-debugging-port=9222 --remote-allow-origins=http://localhost:9222 |
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
import board | |
import digitalio | |
import time | |
import usb_hid | |
from adafruit_hid.keyboard import Keyboard | |
from adafruit_hid.keycode import Keycode | |
# Initialize the button on A0 | |
button = digitalio.DigitalInOut(board.A0) | |
button.direction = digitalio.Direction.INPUT | |
button.pull = digitalio.Pull.UP # Enable internal pull-up resistor | |
# Set up HID keyboard | |
kbd = Keyboard(usb_hid.devices) | |
# Track button state for latching behavior | |
last_button_state = button.value | |
while True: | |
# Check if the button state has changed | |
current_button_state = button.value | |
print(button.value) | |
if current_button_state != last_button_state: | |
last_button_state = current_button_state # Update last state | |
# Only proceed if the button was just pressed (went from HIGH to LOW) | |
if not current_button_state: # Button was pressed | |
print("Button Toggled") # Debugging: Print button toggle status | |
kbd.press(Keycode.CONTROL, Keycode.SHIFT, Keycode.ALT, Keycode.M) | |
time.sleep(0.1) # Debounce delay | |
kbd.release_all() # Release all keys | |
time.sleep(0.05) # Polling delay |
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 python3 | |
import dbus | |
import requests | |
import subprocess | |
import time | |
import websocket | |
import json | |
def send_dbus_notification(title, message): | |
bus = dbus.SessionBus() | |
notify_service = bus.get_object('org.freedesktop.Notifications', '/org/freedesktop/Notifications') | |
notify_interface = dbus.Interface(notify_service, 'org.freedesktop.Notifications') | |
notify_interface.Notify("Python Script", 0, "", title, message, [], {}, -1) | |
def get_chrome_tabs(): | |
"""Fetches the list of open tabs in Chrome via the remote debugging API.""" | |
try: | |
response = requests.get("http://localhost:9222/json") | |
tabs = response.json() | |
return tabs | |
except requests.exceptions.RequestException as e: | |
print("Error connecting to Chrome remote debugging:", e) | |
return [] | |
def find_meet_tab(): | |
meet_url_fragment = "meet.google.com" | |
tabs = get_chrome_tabs() | |
for tab in tabs: | |
if meet_url_fragment in tab['url'] and tab['type'] != 'service_worker': | |
return tab # Return the tab data if Google Meet tab is found | |
return None | |
def is_meet_focused(): | |
"""Checks if the currently active window title contains 'Google Meet'.""" | |
try: | |
window_title = subprocess.check_output("xdotool getwindowfocus getwindowname", shell=True).decode("utf-8").strip() | |
return "Meet" in window_title | |
except subprocess.CalledProcessError: | |
print("Could not determine the active window title.") | |
return False | |
def focus_or_open_meet(): | |
meet_tab = find_meet_tab() | |
if meet_tab: | |
# Check if the active window is already on Google Meet | |
if is_meet_focused(): | |
print("Google Meet tab is already focused. Sending Ctrl+D to mute/unmute.") | |
subprocess.run("xdotool key --clearmodifiers ctrl+d", shell=True) | |
return | |
print(f"Found Google Meet tab: {meet_tab['title']}") | |
# Activate the Chrome window containing the Google Meet tab | |
subprocess.run("xdotool search --name 'Google Chrome' windowactivate", shell=True) | |
time.sleep(0.1) # Allow the window to activate | |
# Connect to the WebSocket to bring the tab to the front | |
ws_url = meet_tab['webSocketDebuggerUrl'] | |
try: | |
ws = websocket.create_connection(ws_url) | |
bring_to_front_command = { | |
"id": 1, | |
"method": "Page.bringToFront" | |
} | |
ws.send(json.dumps(bring_to_front_command)) | |
ws.close() | |
print("Tab has been brought to the front.") | |
except Exception as e: | |
print("Failed to bring tab to the front:", e) | |
else: | |
send_dbus_notification("Meeter", "No Meet instance running") | |
# Run the function | |
focus_or_open_meet() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment