Guest User

Dash Optirun-Adder

a guest
Nov 10th, 2012
244
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/python
  2. # By Kasper Holbek Jensen
  3. import shutil
  4. import os
  5. print os.path.abspath(".local")
  6. #for file in os.listdir("."):
  7. #   print file
  8. program = raw_input("Enter app name: ")
  9.  
  10. home = os.path.expanduser("~")
  11. os.chdir(home+'/.local/share/applications')
  12.  
  13. def checker(n):
  14.     return os.path.exists("/usr/share/applications/"+n+".desktop")
  15.  
  16. if not checker(program):
  17.     if checker(program.lower()):
  18.         program = program.lower()
  19.     elif checker(program.capitalize()):
  20.         program = program.capitalize()
  21.     else:
  22.         print("Can't find the application :( Try different capitalization, or browse to \n/usr/share/applications/"
  23.         "and find the appropriate .desktop file.\nRemember NOT to write the .dekstop extention when prompted for name!\n")
  24.  
  25.  
  26. try:
  27.     shutil.copy("/usr/share/applications/"+program+".desktop",home+'/.local/share/applications')
  28. except:
  29.     pass
  30.  
  31. try:
  32.     f1 = open(program+".desktop","r")
  33.     whole = f1.readlines()
  34.     f1.close
  35.     f2 = open(program+".desktop.tmp","w")
  36.  
  37.  
  38.     for line in whole:
  39.         if "Exec" in line:
  40.             exe = line.split("=")
  41.             f2.write(exe[0]+"= optirun "+exe[1])
  42.         else:  
  43.             f2.write(line)
  44.    
  45.     f2.close
  46.    
  47.     shutil.move(program+".desktop.tmp",program+".desktop")
  48. except:
  49.     pass
RAW Paste Data