Is there a way to make docky available only in one workspace and not in any other workspace in Ubuntu 14.04.
A background script to make docky run on specific workspaces (or not)
Based on exactly the same mechanism as this answer, below a background script that starts/stops the
Docky launcher, depending on the current workspace.
The mechanism itself is pretty much tested out. Having said that, in the linked question it is tested with setting different Unity Launchers and setting different wallpapers per workspace, not starting/stopping
Docky. That should however make no difference whatsoever, and in the hours I tested it, it ran without a single error.
How to use
The script needs
sudo apt-get install wmctrl
Copy the script below into an empty file, save it as
Test-run the script:
Start the script with the command:
Now Docky runs on all workspaces. Navigate to the workspaces you don't want
Dockyto appear and run (while on the workspace):
pkill docky, do not close docky from its own menu!
- That's pretty much it. If you want to change the setting simply either start or kill docky on the workspace you'd like it to run or not; the script will remember your preference.
If all works fine, add it to your startup applications: Dash > Startup Applications > Add the command:
/bin/bash -c "sleep 15&&python3 /path/to/docky_perworkspace.py"
#!/usr/bin/env python3 import subprocess import os import time datadir = os.environ["HOME"]+"/.config/docky_run" if not os.path.exists(datadir): os.makedirs(datadir) workspace_data = datadir+"/docky_set_" def get_runs(): try: subprocess.check_output(["pgrep", "docky"]).decode("utf-8") return True except: return False def get_res(): # get resolution xr = subprocess.check_output(["xrandr"]).decode("utf-8").split() pos = xr.index("current") return [int(xr[pos+1]), int(xr[pos+3].replace(",", "") )] def current(): # get the current viewport res = get_res() vp_data = subprocess.check_output( ["wmctrl", "-d"] ).decode("utf-8").split() dt = [int(n) for n in vp_data.split("x")] cols = int(dt/res) curr_vpdata = [int(n) for n in vp_data.split(",")] curr_col = int(curr_vpdata/res)+1 curr_row = int(curr_vpdata/res) return str(curr_col+curr_row*cols) curr_ws1 = current() runs1 = get_runs() while True: time.sleep(1) runs2 = get_runs() curr_ws2 = current() datafile = workspace_data+curr_ws2 if curr_ws2 == curr_ws1: if runs2 != runs1: open(datafile, "wt").write(str(runs2)) else: if not os.path.exists(datafile): open(datafile, "wt").write(str(runs2)) else: curr_set = eval(open(datafile).read()) if all([curr_set == True, runs2 == False]): subprocess.Popen(["docky"]) elif all([curr_set == False, runs2 == True]): subprocess.Popen(["pkill", "docky"]) curr_ws1 = curr_ws2 runs1 = get_runs()
The script keeps track of the current workspace (no matter how many workspaces you have). Per workspace, a file is created in
/.config/docky_run, in which is "written" if docky should be present or not on the referring workspace (
If you stay on the same workspace, but docky is either started or killed (its
pid appears or ends), the script "understands" it is you who made the change on the referring workspace, and the file is updated.
If the workspace changes however, the script sees if the file exists, reads it and either starts or kills docky (or does nothing if not necessary), according to the content of the file and the current situation. If the file does not exist yet (because you are using the workspace for the first time since you started the script for the first time), the file is created and set to the current (last) situation.
Because settings per workspace are remembered in files, they will be remembered even after a restart.