Created
December 20, 2021 14:25
-
-
Save xopr/8ff9d4bc84e56c4f26c0c567bde70ab6 to your computer and use it in GitHub Desktop.
Creates a panel object launcher in MATE desktop
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
#!/usr/bin/env bash | |
addPanelItem() { | |
PANEL_PATH=~/.config/mate/panel2.d/default/launchers/ | |
echo -ne $1 | |
filename=$(basename -- "$1") | |
extension="${filename##*.}" | |
filename="${filename%.*}" | |
PANEL_FILE="${PANEL_PATH}${filename}.desktop" | |
if [[ -f "$PANEL_FILE" ]]; then | |
echo -e "\texists" | |
return 1 | |
fi | |
# Determine next object index | |
N=$(dconf read /org/mate/panel/general/object-id-list|sed 's/,/\n/g'|grep "'object-[0-9][0-9]*'"|grep -o "[0-9]*"|sort -nr|head -n1 | |
) | |
((N++)) | |
POSITION=$((75+N*50)) | |
# Custom name or base filename | |
if [[ $2 == "" ]]; then | |
NAME=$filename | |
else | |
NAME=$2 | |
fi | |
# Custom icon or default launcher icon | |
if [[ $3 == "" ]]; then | |
ICON="mate-panel-launcher" | |
else | |
ICON=$3 | |
fi | |
# Terminal | |
if [[ $4 == "" ]]; then | |
TERMINAL="false" | |
else | |
TERMINAL="true" | |
fi | |
cat <<EOF > $PANEL_FILE | |
#!/usr/bin/env xdg-open | |
[Desktop Entry] | |
Version=1.0 | |
Type=Application | |
Terminal=$TERMINAL | |
Icon=$ICON | |
Exec=$1 | |
Name=$NAME | |
EOF | |
dconf load / << EOF | |
[org/mate/panel/objects/object-${N}] | |
launcher-location='${filename}.desktop' | |
object-type='launcher' | |
panel-right-stick=false | |
position=$POSITION | |
toplevel-id='top' | |
EOF | |
if [ $? -ne 0 ]; then | |
echo -e "\tfailed to create panel object" | |
return 1 | |
fi | |
LIST=$(dconf read /org/mate/panel/general/object-id-list | sed -rne "s/(.*)'\]/\1', 'object-${N}']/gip") | |
dconf write /org/mate/panel/general/object-id-list "$LIST" | |
if [ $? -ne 0 ]; then | |
echo -e "\tfailed to add panel object to the list" | |
return 1 | |
fi | |
echo -e "\tcreated" | |
return 0 | |
} | |
#addPanelItem "application" ["title"] ["icon"] [runInTerminal] | |
# "application" is mandatory, rest is optional | |
addPanelItem "$HOME/bin/brightness.py" "Brightness" "/usr/share/icons/mate/scalable/status/display-brightness-symbolic.svg" | |
# You might need to run `killall -s SIGUSR1 mate-panel` if the panel was not updating |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment