I wrote a python script to implement this. So here is my config:
bindsym $mod+d exec /path/to/script.py
And my script contains the following, apologies for the verbosity:
#!/usr/bin/python3
import subprocess
import json
from os.path import expanduser
def get_workspace():
test = subprocess.Popen(["i3-msg","-t","get_workspaces"], stdout=subprocess.PIPE)
output = test.communicate()[0]
data = json.loads(output.decode())
data = sorted(data, key=lambda k: k['name'])
for i in data:
if(i['focused']):
return i['name']
home = expanduser("~")
applications = open(home+"/.cache/dmenu_run")
dmenu_run = subprocess.Popen(["dmenu","-b"], stdout=subprocess.PIPE, stdin=applications)
output = (dmenu_run.communicate()[0]).decode().strip()
subprocess.Popen(["i3-msg","workspace "+get_workspace()+"; exec " + output], stdout=subprocess.PIPE)
The script simply:
- Pipes the current dmenurun cache (located at ~/.cache/dmenurun) of applications to dmenu
- Gets the result from dmenu and calls
i3msg 'workspace <current>; exec <dmenu_result>'
where current
is the current workspace and dmenu_result
is what you enter into the dmenu prompt