Last active 1729621737

Simple bash script to launch or raise Logseq and position it on the right side of the screen

matthew's Avatar matthew revised this gist 1729621737. Go to revision

No changes

matthew's Avatar Matthew Weier O'Phinney revised this gist 1680116271. Go to revision

1 file changed, 10 insertions, 5 deletions

logseq-up.sh

@@ -32,22 +32,27 @@ get_geometry() {
32 32 }
33 33
34 34 is_logseq_running() {
35 - if ! wmctrl -x -l | grep -q "logseq.Logseq"; then
35 + echo "Checking if logseq is running"
36 + if ! flatpak ps | grep -q "com.logseq.Logseq"; then
37 + echo "Logseq IS NOT running"
36 38 return 1
37 39 fi
38 40
41 + echo "Logseq IS running"
39 42 return 0
40 43 }
41 44
42 45 if ! is_logseq_running; then
46 + echo "Starting Logseq"
43 47 # This launches logseq, and detaches it from this script's process
44 - logseq & disown
48 + flatpak run com.logseq.Logseq & disown
45 49
46 50 # The wm_class is not set immediately on launch, so we need to sleep for a
47 51 # moment before positioning. 2 seconds seems to be the sweet spot
52 + echo "Sleeping"
48 53 sleep 2
49 54 fi
50 55
51 - wmctrl -x -R "logseq.Logseq"
52 - wmctrl -x -a "logseq.Logseq"
53 - wmctrl -x -r "logseq.Logseq" -e "$(get_geometry)"
56 + echo "Raising logseq and positioning"
57 + wmctrl -x -r "logseq.Logseq" -e "$(get_geometry)"
58 + wmctrl -x -R "logseq.Logseq"

matthew's Avatar Matthew Weier O'Phinney revised this gist 1679588465. Go to revision

1 file changed, 53 insertions

logseq-up.sh(file created)

@@ -0,0 +1,53 @@
1 + #!/bin/bash
2 + # Launch Logseq and/or raise it.
3 + #
4 + # In all cases, it raises it on the current workspace, and positions it on the
5 + # right half of the screen. Change the logic in get_width(), get_height(), and
6 + # get_geometry() to change positioning and size.
7 + #
8 + # I bind this to <Super><Ctrl>-l, which allows me to launch it at any time.
9 +
10 + get_width() {
11 + local full_width
12 + local half_width
13 + full_width="$(wmctrl -d | grep "\*" | cut -d' ' -f 5 | cut -d'x' -f1)"
14 +
15 + half_width=$((full_width/2))
16 + echo $half_width
17 + }
18 +
19 + get_height() {
20 + wmctrl -d | grep "\*" | cut -d' ' -f 5 | cut -d'x' -f2
21 + }
22 +
23 + get_geometry() {
24 + local width
25 + local height
26 +
27 + width=$(get_width)
28 + height=$(get_height)
29 +
30 + # 100 puts it at a higher z-axis plane, which should put it above other windows
31 + echo "100,${width},0,${width},${height}"
32 + }
33 +
34 + is_logseq_running() {
35 + if ! wmctrl -x -l | grep -q "logseq.Logseq"; then
36 + return 1
37 + fi
38 +
39 + return 0
40 + }
41 +
42 + if ! is_logseq_running; then
43 + # This launches logseq, and detaches it from this script's process
44 + logseq & disown
45 +
46 + # The wm_class is not set immediately on launch, so we need to sleep for a
47 + # moment before positioning. 2 seconds seems to be the sweet spot
48 + sleep 2
49 + fi
50 +
51 + wmctrl -x -R "logseq.Logseq"
52 + wmctrl -x -a "logseq.Logseq"
53 + wmctrl -x -r "logseq.Logseq" -e "$(get_geometry)"
Newer Older