Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # App: Xdotool
- # user options
- min_or_close = 'min' # 'min' or 'close' | 'min' = minimize windows | 'close' = close windows
- # based on active app
- Display_Dialog_Name_of_Active_App = 'off' # 'on' or 'off' | To Minimize or Close Windows, Set Display_Dialog_Name_of_Active_App = 'off'
- list_close_windows_of_activeApp = []
- list_min_windows_of_activeApp = []
- # end of user options
- import time
- winClass = window.get_active_class()
- winClass_split = winClass.split(".")
- winClass_use = winClass_split[1]
- if Display_Dialog_Name_of_Active_App == 'on':
- dialog.info_dialog("Name of Active App",
- "Name of Active App: '%s'\n\nTo Minimize or Close Windows, Set Display_Dialog_Name_of_Active_App = 'off'" % (winClass_use))
- quit()
- id_target = system.exec_command("xdotool getwindowfocus")
- id_ex = system.exec_command("xdotool search --onlyvisible --class 'Nemo-desktop'")
- id_window_activeApp = system.exec_command("xdotool search --onlyvisible --class '%s'" % winClass_use)
- list_id_window_activeApp = id_window_activeApp.splitlines()
- countitems_list = len(list_id_window_activeApp)
- # go_min_or_close ?
- len_list_close = len(list_close_windows_of_activeApp)
- len_list_min = len(list_min_windows_of_activeApp)
- plus = len_list_close + len_list_min
- if plus == 0:
- go_min_or_close = 1
- else:
- go_min_or_close = 0
- # end - go_min_or_close ?
- if countitems_list == 1:
- os.system("notify-send 'Script 16 for AutoKey' 'Done!'")
- quit()
- if countitems_list > 1 and min_or_close == 'close' and go_min_or_close == 1 and winClass_use != 'Gedit':
- for i in list_id_window_activeApp:
- if i != id_target and i != id_ex:
- time.sleep(0.1)
- system.exec_command("xdotool windowclose %s" % i)
- os.system("notify-send 'Script 16 for AutoKey' 'Done!'")
- quit()
- if countitems_list > 1 and min_or_close == 'close' and go_min_or_close == 1 and winClass_use == 'Gedit':
- # for Gedit
- list_id_window_activeApp_del_name_gedit_and_others = []
- if winClass_use == 'Gedit':
- for i in list_id_window_activeApp:
- name_by_id = system.exec_command("xdotool getwindowname %s" % i)
- if name_by_id != 'gedit':
- if i != id_target:
- if i != id_ex:
- list_id_window_activeApp_del_name_gedit_and_others.append(i)
- for i in list_id_window_activeApp_del_name_gedit_and_others:
- time.sleep(0.1)
- system.exec_command("xdotool windowactivate %s" % i)
- time.sleep(0.3)
- os.system("xdotool key Alt_L+F4")
- os.system("notify-send 'Script 16 for AutoKey' 'Done!'")
- quit()
- # end - for Gedit
- if countitems_list > 1 and min_or_close == 'min' and go_min_or_close == 1 :
- for i in list_id_window_activeApp:
- if i != id_target and i != id_ex:
- time.sleep(0.1)
- system.exec_command("xdotool windowminimize %s" % i)
- os.system("notify-send 'Script 16 for AutoKey' 'Done!'")
- quit()
- if countitems_list > 1 and go_min_or_close == 0:
- if len_list_close > 0:
- for y in list_close_windows_of_activeApp:
- if y == winClass_use:
- go_list_close_windows_of_activeApp = 1
- break
- else:
- go_list_close_windows_of_activeApp = 0
- else:
- go_list_close_windows_of_activeApp = 0
- if go_list_close_windows_of_activeApp == 1 and winClass_use != 'Gedit':
- for i in list_id_window_activeApp:
- if i != id_target and i != id_ex:
- time.sleep(0.1)
- system.exec_command("xdotool windowclose %s" % i)
- os.system("notify-send 'Script 16 for AutoKey' 'Done!'")
- quit()
- if go_list_close_windows_of_activeApp == 1 and winClass_use == 'Gedit':
- # for Gedit
- list_id_window_activeApp_del_name_gedit_and_others = []
- if winClass_use == 'Gedit':
- for i in list_id_window_activeApp:
- name_by_id = system.exec_command("xdotool getwindowname %s" % i)
- if name_by_id != 'gedit':
- if i != id_target:
- if i != id_ex:
- list_id_window_activeApp_del_name_gedit_and_others.append(i)
- for i in list_id_window_activeApp_del_name_gedit_and_others:
- time.sleep(0.1)
- system.exec_command("xdotool windowactivate %s" % i)
- time.sleep(0.3)
- os.system("xdotool key Alt_L+F4")
- os.system("notify-send 'Script 16 for AutoKey' 'Done!'")
- quit()
- # end - for Gedit
- if countitems_list > 1 and go_min_or_close == 0 and go_list_close_windows_of_activeApp == 0:
- if len_list_min > 0:
- for e in list_min_windows_of_activeApp:
- if e == winClass_use:
- go_list_min_windows_of_activeApp = 1
- break
- else:
- go_list_min_windows_of_activeApp = 0
- else:
- go_list_min_windows_of_activeApp = 0
- if go_list_min_windows_of_activeApp == 1:
- for i in list_id_window_activeApp:
- if i != id_target and i != id_ex:
- time.sleep(0.1)
- system.exec_command("xdotool windowminimize %s" % i)
- os.system("notify-send 'Script 16 for AutoKey' 'Done!'")
- quit()
- 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:
- for i in list_id_window_activeApp:
- if i != id_target and i != id_ex:
- time.sleep(0.1)
- system.exec_command("xdotool windowclose %s" % i)
- os.system("notify-send 'Script 16 for AutoKey' 'Done!'")
- quit()
- 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:
- # for Gedit
- list_id_window_activeApp_del_name_gedit_and_others = []
- if winClass_use == 'Gedit':
- for i in list_id_window_activeApp:
- name_by_id = system.exec_command("xdotool getwindowname %s" % i)
- if name_by_id != 'gedit':
- if i != id_target:
- if i != id_ex:
- list_id_window_activeApp_del_name_gedit_and_others.append(i)
- for i in list_id_window_activeApp_del_name_gedit_and_others:
- time.sleep(0.1)
- system.exec_command("xdotool windowactivate %s" % i)
- time.sleep(0.3)
- os.system("xdotool key Alt_L+F4")
- os.system("notify-send 'Script 16 for AutoKey' 'Done!'")
- quit()
- # end - for Gedit
- 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:
- for i in list_id_window_activeApp:
- if i != id_target and i != id_ex:
- time.sleep(0.1)
- system.exec_command("xdotool windowminimize %s" % i)
- os.system("notify-send 'Script 16 for AutoKey' 'Done!'")
- quit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement