Advertisement
Guest User

Untitled

a guest
Jun 17th, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.95 KB | None | 0 0
  1. # App: Xdotool
  2. # user options
  3. min_or_close = 'min' # 'min' or 'close' | 'min' = minimize windows | 'close' = close windows
  4. # based on active app
  5. Display_Dialog_Name_of_Active_App = 'off' # 'on' or 'off' | To Minimize or Close Windows, Set Display_Dialog_Name_of_Active_App = 'off'
  6. list_close_windows_of_activeApp = []
  7. list_min_windows_of_activeApp = []
  8. # end of user options
  9.  
  10. import time
  11. winClass = window.get_active_class()
  12. winClass_split = winClass.split(".")
  13. winClass_use = winClass_split[1]
  14.  
  15. if Display_Dialog_Name_of_Active_App == 'on':
  16. dialog.info_dialog("Name of Active App",
  17. "Name of Active App: '%s'\n\nTo Minimize or Close Windows, Set Display_Dialog_Name_of_Active_App = 'off'" % (winClass_use))
  18. quit()
  19.  
  20. id_target = system.exec_command("xdotool getwindowfocus")
  21. id_ex = system.exec_command("xdotool search --onlyvisible --class 'Nemo-desktop'")
  22. id_window_activeApp = system.exec_command("xdotool search --onlyvisible --class '%s'" % winClass_use)
  23. list_id_window_activeApp = id_window_activeApp.splitlines()
  24. countitems_list = len(list_id_window_activeApp)
  25.  
  26. # go_min_or_close ?
  27.  
  28. len_list_close = len(list_close_windows_of_activeApp)
  29. len_list_min = len(list_min_windows_of_activeApp)
  30. plus = len_list_close + len_list_min
  31. if plus == 0:
  32. go_min_or_close = 1
  33. else:
  34. go_min_or_close = 0
  35.  
  36. # end - go_min_or_close ?
  37.  
  38. if countitems_list == 1:
  39. os.system("notify-send 'Script 16 for AutoKey' 'Done!'")
  40. quit()
  41.  
  42. if countitems_list > 1 and min_or_close == 'close' and go_min_or_close == 1 and winClass_use != 'Gedit':
  43. for i in list_id_window_activeApp:
  44.  
  45. if i != id_target and i != id_ex:
  46. time.sleep(0.1)
  47. system.exec_command("xdotool windowclose %s" % i)
  48. os.system("notify-send 'Script 16 for AutoKey' 'Done!'")
  49. quit()
  50.  
  51. if countitems_list > 1 and min_or_close == 'close' and go_min_or_close == 1 and winClass_use == 'Gedit':
  52. # for Gedit
  53. list_id_window_activeApp_del_name_gedit_and_others = []
  54. if winClass_use == 'Gedit':
  55. for i in list_id_window_activeApp:
  56. name_by_id = system.exec_command("xdotool getwindowname %s" % i)
  57. if name_by_id != 'gedit':
  58. if i != id_target:
  59. if i != id_ex:
  60. list_id_window_activeApp_del_name_gedit_and_others.append(i)
  61. for i in list_id_window_activeApp_del_name_gedit_and_others:
  62. time.sleep(0.1)
  63. system.exec_command("xdotool windowactivate %s" % i)
  64. time.sleep(0.3)
  65. os.system("xdotool key Alt_L+F4")
  66. os.system("notify-send 'Script 16 for AutoKey' 'Done!'")
  67. quit()
  68. # end - for Gedit
  69.  
  70. if countitems_list > 1 and min_or_close == 'min' and go_min_or_close == 1 :
  71. for i in list_id_window_activeApp:
  72.  
  73. if i != id_target and i != id_ex:
  74. time.sleep(0.1)
  75. system.exec_command("xdotool windowminimize %s" % i)
  76. os.system("notify-send 'Script 16 for AutoKey' 'Done!'")
  77. quit()
  78.  
  79. if countitems_list > 1 and go_min_or_close == 0:
  80.  
  81. if len_list_close > 0:
  82. for y in list_close_windows_of_activeApp:
  83. if y == winClass_use:
  84. go_list_close_windows_of_activeApp = 1
  85. break
  86. else:
  87. go_list_close_windows_of_activeApp = 0
  88. else:
  89. go_list_close_windows_of_activeApp = 0
  90.  
  91. if go_list_close_windows_of_activeApp == 1 and winClass_use != 'Gedit':
  92. for i in list_id_window_activeApp:
  93.  
  94. if i != id_target and i != id_ex:
  95. time.sleep(0.1)
  96. system.exec_command("xdotool windowclose %s" % i)
  97. os.system("notify-send 'Script 16 for AutoKey' 'Done!'")
  98. quit()
  99.  
  100. if go_list_close_windows_of_activeApp == 1 and winClass_use == 'Gedit':
  101. # for Gedit
  102. list_id_window_activeApp_del_name_gedit_and_others = []
  103. if winClass_use == 'Gedit':
  104. for i in list_id_window_activeApp:
  105. name_by_id = system.exec_command("xdotool getwindowname %s" % i)
  106. if name_by_id != 'gedit':
  107. if i != id_target:
  108. if i != id_ex:
  109. list_id_window_activeApp_del_name_gedit_and_others.append(i)
  110. for i in list_id_window_activeApp_del_name_gedit_and_others:
  111. time.sleep(0.1)
  112. system.exec_command("xdotool windowactivate %s" % i)
  113. time.sleep(0.3)
  114. os.system("xdotool key Alt_L+F4")
  115. os.system("notify-send 'Script 16 for AutoKey' 'Done!'")
  116. quit()
  117. # end - for Gedit
  118.  
  119. if countitems_list > 1 and go_min_or_close == 0 and go_list_close_windows_of_activeApp == 0:
  120.  
  121. if len_list_min > 0:
  122. for e in list_min_windows_of_activeApp:
  123. if e == winClass_use:
  124. go_list_min_windows_of_activeApp = 1
  125. break
  126. else:
  127. go_list_min_windows_of_activeApp = 0
  128. else:
  129. go_list_min_windows_of_activeApp = 0
  130. if go_list_min_windows_of_activeApp == 1:
  131. for i in list_id_window_activeApp:
  132. if i != id_target and i != id_ex:
  133. time.sleep(0.1)
  134. system.exec_command("xdotool windowminimize %s" % i)
  135. os.system("notify-send 'Script 16 for AutoKey' 'Done!'")
  136. quit()
  137.  
  138. if countitems_list > 1 and winClass_use != 'Gedit' and min_or_close == 'close' and go_list_min_windows_of_activeApp == 0 and go_list_close_windows_of_activeApp == 0 and go_min_or_close == 0:
  139. for i in list_id_window_activeApp:
  140. if i != id_target and i != id_ex:
  141. time.sleep(0.1)
  142. system.exec_command("xdotool windowclose %s" % i)
  143. os.system("notify-send 'Script 16 for AutoKey' 'Done!'")
  144. quit()
  145.  
  146. if countitems_list > 1 and winClass_use == 'Gedit' and min_or_close == 'close' and go_list_min_windows_of_activeApp == 0 and go_list_close_windows_of_activeApp == 0 and go_min_or_close == 0:
  147. # for Gedit
  148. list_id_window_activeApp_del_name_gedit_and_others = []
  149. if winClass_use == 'Gedit':
  150. for i in list_id_window_activeApp:
  151. name_by_id = system.exec_command("xdotool getwindowname %s" % i)
  152. if name_by_id != 'gedit':
  153. if i != id_target:
  154. if i != id_ex:
  155. list_id_window_activeApp_del_name_gedit_and_others.append(i)
  156. for i in list_id_window_activeApp_del_name_gedit_and_others:
  157. time.sleep(0.1)
  158. system.exec_command("xdotool windowactivate %s" % i)
  159. time.sleep(0.3)
  160. os.system("xdotool key Alt_L+F4")
  161. os.system("notify-send 'Script 16 for AutoKey' 'Done!'")
  162. quit()
  163. # end - for Gedit
  164.  
  165. if countitems_list > 1 and min_or_close == 'min' and go_list_min_windows_of_activeApp == 0 and go_list_close_windows_of_activeApp == 0 and go_min_or_close == 0:
  166.  
  167. for i in list_id_window_activeApp:
  168. if i != id_target and i != id_ex:
  169. time.sleep(0.1)
  170. system.exec_command("xdotool windowminimize %s" % i)
  171. os.system("notify-send 'Script 16 for AutoKey' 'Done!'")
  172. quit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement