commit c4834e58b1a5efd44a120a61e8372d8c8a12ec73 Author: Raoul Branten Date: Mon May 19 18:10:07 2025 +0200 init Scripts meant to be called by keyboard shortcut diff --git a/mediacontrol b/mediacontrol new file mode 100755 index 0000000..9c9d79f --- /dev/null +++ b/mediacontrol @@ -0,0 +1,73 @@ +#!/bin/bash + +# 2022 R. Branten +# Updated 2024 +# ---- +# custom control shortcut file +# start spotify in the brave browser and make it the first tab +# ---- +# https://specifications.freedesktop.org/mpris-spec/latest/Player_Interface.html + +# check if spotify is active on the dbus +BUS=$(dbus-send --print-reply --dest=org.freedesktop.DBus /org/freedesktop/DBus org.freedesktop.DBus.ListNames | grep -i spotify | sed -r 's/ |string|[\"]//g') +CONTROL="spotify" +if [ -z "${BUS}" ]; then + # spotify not active, check brave browser + BUS=$(dbus-send --print-reply --dest=org.freedesktop.DBus /org/freedesktop/DBus org.freedesktop.DBus.ListNames | grep -i brave | sed -r 's/ |string|[\"]//g') + CONTROL="brave" +fi + +if [ -z "${BUS}" ]; then + # spotify not active, check clementine + BUS=$(dbus-send --print-reply --dest=org.freedesktop.DBus /org/freedesktop/DBus org.freedesktop.DBus.ListNames | grep -i clementine | sed -r 's/ |string|[\"]//g') + CONTROL="brave" +fi + +if [ -z "${BUS}" ]; then + # nothing to control + notify-send "Nothing to control" + exit +fi + +# extract and set argument +case $1 in + pause) + # for example space was pressed + dbus-send --print-reply --dest=$BUS /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.PlayPause + SENDNOTIFICATION=true + ;; + next) + # for example alt+Right was pressed + dbus-send --print-reply --dest=$BUS /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Next + SENDNOTIFICATION=true + ;; + previous) + # for example alt+Left was pressed + SENDNOTIFICATION=true + dbus-send --print-reply --dest=$BUS /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Previous + ;; + shuffle) + # for example alt+s was pressed + if [[ "$CONTROL" == "spotify" ]]; then + notify-send "Shuffle on/off" + SENDNOTIFICATION=false + # not clear if shuffle is implemented yet, TESTED AS NOT WORKING + dbus-send --print-reply --dest=$BUS /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Shuffle + else + notify-send "Shuffle not implemented" + exit + fi + ;; + *) + exit + ;; +esac + +# status can be: Playing, Paused or Stopped +status=`dbus-send --print-reply --dest=$BUS /org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.Get string:'org.mpris.MediaPlayer2.Player' string:'PlaybackStatus'|egrep -A 1 "string"|cut -b 26-|cut -d '"' -f 1|egrep -v ^$` +artist=`dbus-send --print-reply --dest=$BUS /org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.Get string:'org.mpris.MediaPlayer2.Player' string:'Metadata'|egrep -A 2 "artist"|egrep -v "artist"|egrep -v "array"|cut -b 27-|cut -d '"' -f 1|egrep -v ^$` +album=`dbus-send --print-reply --dest=$BUS /org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.Get string:'org.mpris.MediaPlayer2.Player' string:'Metadata'|egrep -A 1 "album"|egrep -v "album"|cut -b 44-|cut -d '"' -f 1|egrep -v ^$` +title=`dbus-send --print-reply --dest=$BUS /org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.Get string:'org.mpris.MediaPlayer2.Player' string:'Metadata'|egrep -A 1 "title"|egrep -v "title"|cut -b 44-|cut -d '"' -f 1|egrep -v ^$` +notify-send Media: "${status}\n${artist} - ${title}" + +exit diff --git a/windowmanagement.sh b/windowmanagement.sh new file mode 100755 index 0000000..3726514 --- /dev/null +++ b/windowmanagement.sh @@ -0,0 +1,69 @@ +#!/bin/bash + +# 2022 R. Branten +# ---- +# position windows +# ---- +# get witdh of screen, not needed as percentages work just fine + +# check if xdotool is installed +if ! command -v xdotool &> /dev/null +then + notify-send WindowManagement: "xdotool not installed" + exit +fi + +SCREENWIDTH=$(xdpyinfo | awk '/dimensions/{print $2}' | grep -oE ^[[:digit:]]\+) +SCREENHEIGHT=$(xdpyinfo | awk '/dimensions/{print $2}' | grep -oE [[:digit:]]\+$) +PANELHEIGHT=$(xdotool getwindowgeometry $(xdotool search --onlyvisible --class 'panel') | awk '/Geometry/{print $2}' | grep -oE [[:digit:]]\+$) +HEIGHT=$SCREENHEIGHT-$PANELHEIGHT + +# extract and set argument +case $1 in + center) # 100% window size centered + WIDTH=100% + HEIGHT=100% + XPOS=0% + ;; + center50) # 50% window size smack in the middle + WIDTH=50% + XPOS=25% + ;; + left25) # 25% window size left side of screen + WIDTH=25% + XPOS=0% + ;; + right25) # 25% window size right side of screen + WIDTH=25% + XPOS=75% + ;; + left50) # 25% window size left side of screen + WIDTH=50% + XPOS=0% + ;; + right50) # 25% window size right side of screen + WIDTH=50% + XPOS=50% + ;; + centerleft25) # 25% window size left side of center screen + WIDTH=25% + XPOS=25% + ;; + centerright25) # 25% window size right side of center screen + WIDTH=25% + XPOS=50% + ;; + *) + exit + ;; +esac + +# resize window +#xdotool getactivewindow windowsize $WIDTH $HEIGHT +xdotool getactivewindow windowsize $WIDTH 95% + +# move window to location +xdotool getactivewindow windowmove $XPOS 0.1 + +# display alert window +notify-send WindowManagement: "${1}"