0 کاربر و 3 مهمان درحال مشاهده موضوع.
#!/usr/bin/env python3import subprocessimport osimport timeimport shutilhome = os.environ["HOME"]desktop_dir = desktop_dir = home+"/"+"Desktop"data_dirstr = home+"/desktop_data/desktop_"get = lambda cmd: subprocess.check_output(["/bin/bash", "-c", cmd]).decode("utf-8")# get resolutionxr = get("xrandr").split()plus = 2 if xr[xr.index("connected")+1] == "primary" else 1res = [int(n) for n in xr[xr.index("connected")+plus].split("+")[0].split("x")]def get_dt(): # get the current viewport vp_data = subprocess.check_output(["wmctrl", "-d"]).decode("utf-8").split() dt = [int(n) for n in vp_data[3].split("x")] cols = int(dt[0]/res[0]) curr_vpdata = [int(n) for n in vp_data[5].split(",")] curr_col = int(curr_vpdata[0]/res[0])+1; curr_row = int(curr_vpdata[1]/res[1]) return str(curr_col+curr_row*cols)curr_dt1 = get_dt()while True: time.sleep(1) curr_dt2 = get_dt() # alter the set of links when workspace changes if not curr_dt1 == curr_dt2: datafolder = data_dirstr+curr_dt2 for f in os.listdir(desktop_dir): subject = desktop_dir+"/"+f # uncomment one of the two lines below if os.path.islink(subject): # uncomment for only folders (links to) per workspace # if os.path.islink(subject) or subject.endswith(".desktop") : # uncomment for folders and .desktop files per workspace # os.remove(subject) for f in os.listdir(datafolder): subject = datafolder+"/"+f; target = desktop_dir+"/"+f if os.path.islink(subject): os.symlink(os.readlink(subject), target) else: shutil.copy(subject,target) curr_dt1 = curr_dt2