Return to repo list


Contextual launcher/tag shortcut methodology; intended for dwm.
Return to

commit 352cc2347577c3e93552f17290b23408f02c74be
parent 17e224ce0a4de4dd796d8d3584a05ec97e082f9e
Author: Erik Letson <>
Date:   Fri, 17 Jul 2020 01:36:50 -0500

Usage instructions in the README

MREADME | 102++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- | 6++++--
2 files changed, 105 insertions(+), 3 deletions(-)

diff --git a/README b/README @@ -1 +1,101 @@ -todo + - Smartlaunch - +A method for contextually-aware rules-based application/tag view change shortcuts in dwm. + +01. What is Smartlaunch? + + Smartlaunch is a shell script and a set of instructions that are meant to be used in conjunction with + dwm ( to achieve a *certain kind of application launching behavior*. The project + consists of two parts: a script that launches an command as long as no window matching a given WM_NAME + xproperty exists, and a set of instructions and examples on how to use this script with dwm to create + keyboard shortcuts that can launch applications and then *function as quick ways to access those same + application once they are already running* (for example, press MOD+F to launch Firefox, then press MOD+F + again anytime to return immediately to the tag that Firefox was opened in, as long as Firefox is still there). + + The basic usage idea is to create a 'rule' in config.h ( for + some application that you want to have a dedicated tag for (for instance, Firefox might be dedicated to tag 8, + meaning that every time you open an instance of Firefox, it will appear in tag 8), and then create a key + combination to launch that application *in the context of the smartlaunch script*, and to also link that same + key combination to a dwm command that causes you to shift your view to the tag associated with said application. + + Here is the step-by-step usage example: + + i. Create a rule for your application in config.h setting it to a specific tag + ii. Create a command to launch that application using in config.h + iii. Create a key combination to launch that command in config.h + iv. Also assign that same key combination to switch views to the application's tag in config.h + + Once this is done, you will have a context-aware shortcut for launching an application and viewing it + immediately in the launched tab, as well as a way to *immediately switch to that same tab later as long as the + application's window is still running.* If this sounds like desirable behavior to you, Smartlaunch can help! + +02. Installation & Dependencies + + There are no install instructions. Simply place the script somewhere and then begin incorporating + it into your config.h. + + Smartlaunch has the following dependencies: + + xwininfo + xprop + dwm (if you want to get any actual use out of the script) + + To install these on Gentoo, run: + + # emerge x11-apps/xwininfo x11-apps/xprop x11-wm/dwm + + These programs are also available on other distributions, or in source code format from + and + +03. Usage Instructions + + takes two arguments: a string matching all or part of a WM_NAME xproperty, and a command to launch + if that name cannot be found among existing windows. + + Here is an example: + + $ ./ Firefox firefox + + The above example will launch the command 'firefox' if it cannot find any existing windows who's WM_NAME contain + the string 'Firefox'. You may ask, "How do I find the WM_NAME property of a window?" The simplest way is to run + xprop(1), then click on the window you want to investigate. WM_NAME will be among the properties in the output. + + To include the above example in dwm's config.h, create a command that looks something like this: + + static const char *smartlaunchcmd[] = { "/bin/bash", "-c", "/path/to/ Firefox firefox", NULL } + + This can be bound to a key combination in the 'keys[]' array in config.h. For instance, to bind it to MOD+F: + + { MODKEY, XK_f, spawn, {.v = smartlaunchcmd } }, + + The real use comes with creating a rule to assign the application window to a specific tag in the config.h + 'rules[]' array. For instance, to assign Firefox to tab 8: + + { "Firefox", NULL, NULL, 1 << 8, 0, -1 }, + + Once this is done, you can assign the same key combination from earlier to *also* switch to the tab associated + with the application by the rule. For the examples listed above, that would mean including this *along with + the first MOD+F shortcut* that we already made: + + { MODKEY, XK_f, view, {.ui = 1 << 8 } }, + + Notice that the key combination is *exactly* the same. In dwm, *all* entries for a specific key combination in + the 'keys[]' array will be executed. They do not get overwritten. + + Now, when you press the chosen key combination (MOD+F in the examples), one of two things will happen: + + 1). If there is no window matching the WM_NAME in the command, a new instance of the application + will be started and the view will switch immediately to the tag associated with that application, or: + + 2). If there IS a window matching the WM_NAME in the command, the view will simply switch to the tag + associated with the existing application, and nothing new will be started. + +04. License + + Smartlaunch is licensed under the MIT/Expat license. See the LICENSE file for more details. + +05. Author + + Smartlaunch is developed and maintained by Erik Letson <>. Please direct any questions, + patches, or bug reports to his email. + + There is a browsable git repository for Smartlaunch available at diff --git a/ b/ @@ -1,7 +1,9 @@ #!/bin/bash -PROPNAME=$1 -CMDNAME=$2 +# To use the script, bind it to a key combination in dwm's config.h, and also bind THE SAME KEY to switch to the dedicated tag for the window to be launched. + +PROPNAME=$1 # A string that should match 'NET_WM_NAME' for the target window, in whole or in part. See xprop(1). +CMDNAME=$2 # The command to execute if no matching window is found. WINEXISTS=$(xwininfo -root -tree | grep -o '^[[:space:]]*0x.\{7\}' | while read line; do xprop -id $line | grep "NET_WM_NAME.*$PROPNAME"; done)