obsidian will never launch because pgrep obsidian && i3-msg
will always exit with success status. I understand that you don’t want the keybinding to launch obsidian if there is already an instance of obsidian running, but that’s not the right way to do it. pgrep
will not exit with a non-zero exit code even though it fails to find any process that matches your criteria. Similarly, even though [class=“obsidian”] doesn’t do anything in this case, the call made to i3-msg will still return successfully (it will return an empty list).
What you need to do instead is to just write a shell-script, launch-obsidian.sh
#!/bin/sh
pid="$(pgrep obsidian)"
if [ -z "$pid" ]
then
obsidian &
fi
Then, in your i3 config:
bindsym $mod+o exec ~/path/to/launch-obsidian.sh
Extra info:
That’s not how you use a command criteria. What is it that you’re asking i3 to execute? Specifying a command criteria without giving it a command does nothing.
Generally, command criterias work like this:
[class=obsidian] some_i3_command
Using i3-msg:
i3-msg '[class="obsidian"] some_i3_command'
Also, do consider using command chaining. If you want a keybinding to execute a chain of command (Command_A, Command_B, Command_C), you can do it like this:
bindsym $mod+o Command_A ; Command_B ; Command_C
If you want a command criteria to apply to a multiple commands, use a comma instead
bindsym $mod+o [class="obsidian"] Command_A ; Command_B
Command_A only applies to windows of class “obsidian”
bindsym $mod+o [class="obsidian"] Command_A, Command_B
Both Command_A and Command_B applies to windows of class “obsidian”