i3-py executing commands out of order
I working on a script to switch the workspaces on my displays (similar to: http://i3wm.org/docs/user-contributed...). Approximately one time in five that I run the script, it executes my commands out of order causing some workspaces to be moved twice and others not at all. I was able to fix this by sleeping for 0.1s on each loop, but this is obviously not the ideal way to solve this bug.
How should I be ensuring that each line succeeds before the next is run?
#!/usr/bin/python2.7
from time import sleep
import i3
# save focused workspace
def find_active_workspace():
workspaces = i3.get_workspaces()
for workspace in workspaces:
if workspace['focused'] == True:
return workspace['name']
else:
return False
active_workspace = find_active_workspace()
# move everything
outputs = i3.get_outputs()
for output in range(0, 4):
i3.workspace(outputs[output]['current_workspace'])
i3.command('move', 'workspace to output up')
sleep(0.1)
# restore focus to previously focused
sleep(0.1)
if active_workspace:
i3.command("workspace", active_workspace)
I'm new to scripting so any other comments on the code would also be appreciated.
Thanks!
i3-py is no longer maintained and has a lot of bugs. The current best scripting library is [i3ipc-python](https://github.com/acrisci/i3ipc-python). Even calling out to i3-msg would be better.