Skip to content

Instantly share code, notes, and snippets.

@akshaybaweja
Created July 7, 2021 04:48
Show Gist options
  • Save akshaybaweja/f4ad5da0c90b94a0cc4661ec22da681c to your computer and use it in GitHub Desktop.
Save akshaybaweja/f4ad5da0c90b94a0cc4661ec22da681c to your computer and use it in GitHub Desktop.

Revisions

  1. akshaybaweja created this gist Jul 7, 2021.
    12 changes: 12 additions & 0 deletions getZoomInfo.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,12 @@
    import osascript

    scpt = '''
    set vol to ((output volume of (get volume settings)) + 5)
    if (vol > 100) then set vol to 100
    set volume output volume (vol)
    display notification ((vol) as string)
    '''

    code, out, error = osascript.run(scpt)
    print(code, out, error)
    127 changes: 127 additions & 0 deletions main.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,127 @@
    import serial
    import re
    import osascript
    import keyboard
    from time import sleep
    import threading

    SERIAL_PORT = "/dev/cu.usbmodem14101"
    BAUD_RATE = 9600
    TIMEOUT = 100

    isMuted = True
    lastStatus = False
    lastVolume = 0
    isRunning = True

    DELTA_MULTIPLIER = 10

    print("OPENING SERIAL_PORT '{port}' WITH BAUDRATE {baud}...".format(port = SERIAL_PORT, baud = BAUD_RATE))
    print("\nIMPORTANT!")
    print("To end the program hold Ctrl+C")

    #Opens the serial port specified by SERIAL_PORT with the specified BAUD_RATE
    ser = serial.Serial(SERIAL_PORT, BAUD_RATE, timeout = TIMEOUT)
    ser.flushInput()
    ser.flushOutput()

    def getZoomStatusThread():
    global isMuted
    global lastStatus
    global lastVolume
    global ser

    while isRunning:

    scpt = '''
    property btnTitle : "Mute audio"
    if application "zoom.us" is running then
    tell application "System Events"
    tell application process "zoom.us"
    if exists (menu item btnTitle of menu 1 of menu bar item "Meeting" of menu bar 1) then
    set returnValue to "UNMUTED"
    else
    set returnValue to "MUTED"
    end if
    end tell
    end tell
    else
    set returnValue to ""
    end if
    return returnValue
    '''

    code, out, error = osascript.run(scpt)
    # print(code, out, error)
    if code == 0:
    if out == "MUTED":
    isMuted = True
    deviceColor = "RED"
    elif out == "UNMUTED":
    isMuted = False
    deviceColor = "GREEN"

    code, volume, error = osascript.run('set curVolume to output volume of (get volume settings)')

    if lastStatus != isMuted or lastVolume != volume:
    string2send = '*{vol}#{color}*'.format(vol=volume, color=deviceColor).encode('utf-8')
    ser.write(string2send)
    ser.flushOutput()
    lastStatus = isMuted
    lastVolume = volume

    def getSerialCommands():
    global ser

    while isRunning:
    line = ser.readline().decode('utf-8').replace("\r\n","")
    print(line)

    deltaChange = re.search("\*([-+]?\d+)\*", line)
    if deltaChange:
    delta = int(deltaChange[1]) * DELTA_MULTIPLIER
    if delta > -100 and delta < 100:
    _, currVolume, _ = osascript.run('set curVolume to output volume of (get volume settings)')
    newVolume = int(currVolume) + delta

    if newVolume < 10:
    newVolume = 10
    if newVolume > 100:
    newVolume = 100

    _, _, _ = osascript.run('set volume output volume ' + str(newVolume))
    ser.flushInput()

    else:
    muteCall = re.search("\*(MUTE)\*", line)
    if muteCall:
    keyboard.press_and_release('F17')
    ser.flushInput()

    if __name__ == "__main__":
    try:
    t1 = threading.Thread(target=getZoomStatusThread)
    t2 = threading.Thread(target=getSerialCommands)

    t1.setDaemon(True)
    t2.setDaemon(True)

    t1.start()
    t2.start()

    while True:
    pass
    except KeyboardInterrupt: #When Ctrl+C is pressed, the loop terminates
    isRunning = False

    t1.join()
    t2.join()

    string2send = '*0#RED*'.encode('utf-8')
    ser.write(string2send)
    print("\nThank You for using Zoom Controller")

    #Closes the serial port
    ser.close()