autoconnect-wireless-debugging-linux.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #!/bin/python
  2. # -*- coding: utf-8 -*-
  3. # This script checks your clipboard contents and connects to the wireless debugging bridge if requested
  4. #
  5. # Requirements:
  6. # pyperclip
  7. from threading import Thread
  8. import pyperclip
  9. import os
  10. def main():
  11. if not pyperclip.is_available:
  12. return
  13. connect_action_prefix = 'connect-wireless-debugging://'
  14. previous_clipboard = pyperclip.paste()
  15. while True:
  16. new_clipboard = pyperclip.waitForNewPaste()
  17. print('New item copied: ' + new_clipboard)
  18. if not new_clipboard.startswith(connect_action_prefix):
  19. previous_clipboard = new_clipboard
  20. continue
  21. address = new_clipboard.removeprefix(connect_action_prefix)
  22. result = os.popen('adb connect ' + address).readline()
  23. result = result[0].upper() + result[1:]
  24. if result.startswith('Connected to '):
  25. icon = 'nm-device-wireless'
  26. pyperclip.copy(previous_clipboard)
  27. else:
  28. icon = 'error'
  29. raw_connection_data = new_clipboard.removeprefix(connect_action_prefix)
  30. pyperclip.copy(raw_connection_data)
  31. command = 'notify-send' + \
  32. ' --expire-time 3000' + \
  33. ' --icon ' + icon + \
  34. ' --app-name "Android Wireless Debugging"' + \
  35. ' "' + result + '"'
  36. # 'notify-send' blocks the thread, so it is invoked in the background
  37. Thread(target=os.system, args=[command]).start()
  38. if __name__ == '__main__':
  39. main()