Last active
January 26, 2022 06:38
-
-
Save anecdata/0df3d9bf8ddee2e06f51ccbccfa0feb9 to your computer and use it in GitHub Desktop.
macOS Terminal: open new tab for each serial device, connect with tio, rename the tab to the volume name
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 discotool | |
import subprocess | |
devicesList = discotool.get_identified_devices(drive_info=True) | |
for device in devicesList: | |
if device.repl is None: continue | |
commands = [ | |
# open a new Terminal tab and connect to the device | |
["osascript", "-e", 'tell application "Terminal" to activate',], | |
["osascript", "-e", 'tell application "System Events" to tell process "Terminal" to keystroke "t" using command down',], | |
["osascript", "-e", f'''tell application "Terminal" to do script "tio {device.repl}" in selected tab of the front window''',], | |
] | |
if device.volume: | |
volume_commands = [ | |
# rename the Terminal tab to the volume name [e.g., CIRCUITPY] | |
["osascript", "-e", 'tell application "System Events" to keystroke "i" using {shift down,command down}',], | |
["osascript", "-e", 'tell application "System Events" to keystroke Tab',], | |
["osascript", "-e", f'''tell application "System Events" to keystroke "{device.volume.split("/")[-1]}"''',], | |
["osascript", "-e", 'tell application "System Events" to key code 53',], | |
] | |
commands.extend(volume_commands) | |
for command in commands: | |
subprocess.call(command) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks, @Neradoc, for discotool and starting code.