From 9b19480228d8421c3987a634a602012c953a993e Mon Sep 17 00:00:00 2001 From: neodarz Date: Thu, 5 Sep 2019 07:48:16 +0200 Subject: Add some scripts --- dotfiles/scripts/switch-workspace.py | 45 ++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100755 dotfiles/scripts/switch-workspace.py (limited to 'dotfiles/scripts/switch-workspace.py') diff --git a/dotfiles/scripts/switch-workspace.py b/dotfiles/scripts/switch-workspace.py new file mode 100755 index 0000000..d311c46 --- /dev/null +++ b/dotfiles/scripts/switch-workspace.py @@ -0,0 +1,45 @@ +#!/usr/bin/env python + +from json import loads +from os import popen +from sys import argv + +def ipc_query(req="command", msg=""): + ans = popen("i3-msg -t " + req + " " + msg).readlines()[0] + return loads(ans) + +if __name__ == "__main__": + # Usage & checking args + if len(argv) != 2: + print ("Usage: switch-workspace.py name-of-workspace") + exit(-1) + + newworkspace = argv[1] + + # Retrieving active display + active_display = None + old_display = None + for w in ipc_query(req="get_workspaces"): + if w['focused']: + active_display = w['output'] + if w['name'] == newworkspace: + old_display = w['output'] + if newworkspace.isdigit() and w['num'] == int(newworkspace): + old_display = w['output'] + print (w) + + # Pre-computing commands + if newworkspace.isdigit(): + cmd_show = "workspace number " + newworkspace + else: + cmd_show = "workspace " + newworkspace + cmd_move = "move workspace to output " + active_display + + # Moving workspace to active display + if active_display == old_display: + print (cmd_show) + print (ipc_query(msg=cmd_show)) + else: + cmd="'" + cmd_show + ";" + cmd_move + ";" + cmd_show + "'" + print (cmd) + print (ipc_query(msg=cmd)) -- cgit v1.2.1