Skip to content

Instantly share code, notes, and snippets.

@sahib
Created April 10, 2012 16:59
Show Gist options
  • Save sahib/2352858 to your computer and use it in GitHub Desktop.
Save sahib/2352858 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import os, sys
def find_next_free_x_display(max_tries = 10):
"""
Find the next free X Display by
investigating the Xlocks in /tmp
"""
for i in range(max_tries):
try_path = "/tmp/.X" + str(i) + "-lock"
try:
with open(try_path,"r"):
pass
except:
return i
else:
return -1
def usage():
print("Usage: {0} <appname> or when using wine: {0} wine <appname>".format(sys.argv[0]))
if __name__ == "__main__":
if len(sys.argv) < 2 :
usage()
else:
out = ""
for x in sys.argv[2:]:
out += (" " + x)
display = find_next_free_x_display()
if display != -1:
os.system("xinit $(which " + sys.argv[1] + ")" + out + " -- :" + str(display))
else:
print("Sorry, couldn't find a free X display")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment