Last active
March 29, 2023 18:57
-
-
Save weierophinney/7a48c19bea5165160c9e1465fa83d4ad to your computer and use it in GitHub Desktop.
Logseq launcher. This will launch Logseq if it isn't already, and otherwise raise it on the current workspace, pinned to the right side of the screen.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Launch Logseq and/or raise it. | |
# | |
# In all cases, it raises it on the current workspace, and positions it on the | |
# right half of the screen. Change the logic in get_width(), get_height(), and | |
# get_geometry() to change positioning and size. | |
# | |
# I bind this to <Super><Ctrl>-l, which allows me to launch it at any time. | |
get_width() { | |
local full_width | |
local half_width | |
full_width="$(wmctrl -d | grep "\*" | cut -d' ' -f 5 | cut -d'x' -f1)" | |
half_width=$((full_width/2)) | |
echo $half_width | |
} | |
get_height() { | |
wmctrl -d | grep "\*" | cut -d' ' -f 5 | cut -d'x' -f2 | |
} | |
get_geometry() { | |
local width | |
local height | |
width=$(get_width) | |
height=$(get_height) | |
# 100 puts it at a higher z-axis plane, which should put it above other windows | |
echo "100,${width},0,${width},${height}" | |
} | |
is_logseq_running() { | |
echo "Checking if logseq is running" | |
if ! flatpak ps | grep -q "com.logseq.Logseq"; then | |
echo "Logseq IS NOT running" | |
return 1 | |
fi | |
echo "Logseq IS running" | |
return 0 | |
} | |
if ! is_logseq_running; then | |
echo "Starting Logseq" | |
# This launches logseq, and detaches it from this script's process | |
flatpak run com.logseq.Logseq & disown | |
# The wm_class is not set immediately on launch, so we need to sleep for a | |
# moment before positioning. 2 seconds seems to be the sweet spot | |
echo "Sleeping" | |
sleep 2 | |
fi | |
echo "Raising logseq and positioning" | |
wmctrl -x -r "logseq.Logseq" -e "$(get_geometry)" | |
wmctrl -x -R "logseq.Logseq" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment