Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- import os, sys, time
- 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 silly usage
- """
- print("Usage: {0} [-t <sec>] <appname> or when using wine: {0} wine <appname>".format(sys.argv[0]))
- def check(cond,msg,exit_rc):
- """
- Abort if condition is false
- """
- if cond:
- print(msg)
- usage()
- sys.exit(exit_rc)
- if __name__ == "__main__":
- if len(sys.argv) < 2 :
- usage()
- else:
- timeout = 0
- command = sys.argv[1:]
- # Parse -t option
- if sys.argv[1] == "-t":
- check(len(sys.argv) < 3,"-t needs an argument, Sir.",-1)
- check(len(sys.argv) < 4,"You should also add a command behind -t, Sir.",-2)
- try: timeout = int(sys.argv[2])
- except: check(True,"Cannot convert '" + sys.argv[2] + "' to an integer, Sir.",-3)
- command = sys.argv[3:]
- # Count down if desired
- if timeout > 0:
- print("Will start app in ",end='')
- for second in range(timeout):
- print(str(timeout - second) + "..", end='')
- sys.stdout.flush()
- time.sleep(1)
- print()
- display = find_next_free_x_display()
- if display != -1:
- os.system("xinit $(which " + command[0] + ")" + ' '.join(command[1:]) + " -- :" + str(display))
- else:
- print("Sorry, couldn't find a free X display")
Add Comment
Please, Sign In to add comment