Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save AbdullahAlhariri/efb899c125b9da82f8c5d5204973cd79 to your computer and use it in GitHub Desktop.

Select an option

Save AbdullahAlhariri/efb899c125b9da82f8c5d5204973cd79 to your computer and use it in GitHub Desktop.
I3 dmenu script to control gnome pomodoro through gdbus
#!/usr/bin/env bash
DMENU="dmenu -i -p 'Pomodoro'"
DEST="org.gnome.Pomodoro"
PATH_="/org/gnome/Pomodoro"
IFACE="org.gnome.Pomodoro"
PREFS="org.gnome.pomodoro.preferences"
# --- helpers ---
start_pomodoro() {
local minutes="$1"
local seconds=$((minutes * 60))
gsettings set $PREFS pomodoro-duration "$seconds"
gdbus call --session \
--dest "$DEST" \
--object-path "$PATH_" \
--method "$IFACE.SetState" "pomodoro" 0 >/dev/null
gdbus call --session \
--dest "$DEST" \
--object-path "$PATH_" \
--method "$IFACE.Start" >/dev/null
}
start_break_short() {
local minutes="$1"
local seconds=$((minutes * 60))
gsettings set $PREFS short-break-duration "$seconds"
gdbus call --session \
--dest "$DEST" \
--object-path "$PATH_" \
--method "$IFACE.SetState" "short-break" 0 >/dev/null
gdbus call --session \
--dest "$DEST" \
--object-path "$PATH_" \
--method "$IFACE.Start" >/dev/null
}
start_break_long() {
local minutes="$1"
local seconds=$((minutes * 60))
gsettings set $PREFS long-break-duration "$seconds"
gdbus call --session \
--dest "$DEST" \
--object-path "$PATH_" \
--method "$IFACE.SetState" "long-break" 0 >/dev/null
gdbus call --session \
--dest "$DEST" \
--object-path "$PATH_" \
--method "$IFACE.Start" >/dev/null
}
custom_input() {
local label="$1"
local mode="$2"
minutes=$(echo "" | dmenu -p "$label (minutes)")
[[ -z "$minutes" ]] && exit 0
if ! [[ "$minutes" =~ ^[0-9]+$ ]]; then
notify-send "Invalid number"
exit 1
fi
if [ "$mode" = "pomodoro" ]; then
start_pomodoro "$minutes"
else
start_break_long
fi
}
pause_timer() {
gdbus call --session \
--dest "$DEST" \
--object-path "$PATH_" \
--method "$IFACE.Pause" >/dev/null
}
remove_timer() {
# Stop + reset state (forgets progress)
gdbus call --session \
--dest "$DEST" \
--object-path "$PATH_" \
--method "$IFACE.Stop" >/dev/null
gdbus call --session \
--dest "$DEST" \
--object-path "$PATH_" \
--method "$IFACE.Reset" >/dev/null
}
# --- menu ---
choice=$(printf "\
start
pauze
remove
60p
45p
30p
15p
30b
15b
5b
custom pomodoro
custom break
" | $DMENU)
case "$choice" in
# core controls
start)
start_pomodoro 25
;;
pauze)
pause_timer
;;
remove)
remove_timer
;;
# pomodoros
60p) start_pomodoro 60 ;;
45p) start_pomodoro 45 ;;
30p) start_pomodoro 30 ;;
15p) start_pomodoro 15 ;;
# breaks
30b) start_break_long 30 ;;
15b) start_break_short 15 ;;
5b) start_break_short 5 ;;
# custom
"custom pomodoro")
custom_input "Custom Pomodoro" "pomodoro"
;;
"custom break")
custom_input "Custom Break (long break)" "break"
;;
*)
exit 0
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment