Skip to content

Commit 24da2ab

Browse files
mf-fxMarcus Funch
authored andcommitted
Make autostart program work with snaps, remove case insensitivity from desktop program shortcut script as .desktop files may contain uppercase
1 parent 6eae4ef commit 24da2ab

File tree

2 files changed

+32
-31
lines changed

2 files changed

+32
-31
lines changed

os2borgerpc/desktop/desktop_program_shortcut.sh

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,14 @@
99
# Arguments:
1010
# 1: Use a boolean to decide whether to add or remove the program shortcut
1111
# 2: This argument should specify the name of a program (.desktop-file)
12-
# under /usr/share/applications/ or /var/lib/snapd/desktop/applications/
12+
# under /usr/share/applications/ or /var/lib/snapd/desktop/applications/
13+
# This parameter IS case-sensitive as some applications have
14+
# capitalized characters in their filename.
1315

1416
set -x
1517

16-
lower() {
17-
echo "$@" | tr '[:upper:]' '[:lower:]'
18-
}
19-
20-
ADD=$1
21-
PROGRAM="$(lower "$2")"
18+
ADD="$1"
19+
PROGRAM="$2"
2220

2321
SHADOW=".skjult"
2422

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,45 @@
1-
#!/bin/bash
1+
#!/usr/bin/env sh
22

3-
# DESCRIPTION
3+
# DESCRIPTION
44
# This script either copies a given installed .desktop file to the autostart directory
5-
# or removes a given file from the autostart directory.
5+
# or removes a given file from the autostart directory.
66
#
7-
# To check which scripts are installed on a machine run the script
8-
# "desktop_print_program_list.sh" AKA "Desktop - Vis programliste" with paremeter
7+
# To check which scripts are installed on a machine run the script
8+
# "desktop_print_program_list.sh" AKA "Desktop - Vis programliste" with paremeter
99
# "mulige" to print a full list of eligible files to add to autostart.
1010
#
1111
# PARAMENTERS
12-
# 1. String. The given file's name, either with no extension or with .desktop
13-
# eg. "firefox" or "firefox.desktop". This parameter IS case-sensitive
14-
# as some applications have capitalized characters in their filename.
12+
# 1. String. The given file's name, e.g. firefox, without the .desktop extension.
13+
# This parameter IS case-sensitive as some applications have
14+
# capitalized characters in their filename.
1515
# 2. Checkbox. Check this box to delete a file from the autostart folder instead.
1616

17-
SELECTED=$1
18-
DELETE=$2
17+
set -x
1918

20-
if [[ $SELECTED != *.desktop ]]; then
21-
SELECTED="$SELECTED.desktop"
22-
fi
19+
PROGRAM="$1"
20+
DELETE="$2"
2321

2422
AUTOSTART_DIR="/home/.skjult/.config/autostart"
25-
AUTOSTART_FILE="$AUTOSTART_DIR/$SELECTED"
26-
INSTALLED_APP_FILE="/usr/share/applications/$SELECTED"
2723

28-
if [ "$DELETE" = "True" ]; then
29-
echo "Removing $SELECTED from autostart directory"
30-
31-
rm "$AUTOSTART_FILE"
24+
if [ -f "/var/lib/snapd/desktop/applications/${PROGRAM}_$PROGRAM.desktop" ]; then
3225

33-
exit "$?"
26+
INSTALLED_APP_FILE="/var/lib/snapd/desktop/applications/${PROGRAM}_$PROGRAM.desktop"
27+
AUTOSTART_FILE="$AUTOSTART_DIR/${PROGRAM}_$PROGRAM.desktop"
28+
else
29+
INSTALLED_APP_FILE="/usr/share/applications/$PROGRAM"
30+
AUTOSTART_FILE="$AUTOSTART_DIR/$PROGRAM.desktop"
3431
fi
3532

36-
mkdir -p $AUTOSTART_DIR
33+
mkdir --parents $AUTOSTART_DIR
34+
35+
# Remove it first, partially because ln even with --force cannot replace it if it's a regular file
36+
rm --force "$AUTOSTART_FILE"
3737

38-
echo "Adding $SELECTED to autostart directory"
38+
if [ "$DELETE" != "True" ]; then
3939

40-
cp "$INSTALLED_APP_FILE" "$AUTOSTART_FILE"
40+
echo "Adding $PROGRAM to autostart directory"
4141

42-
exit "$?"
42+
ln --symbolic --force "$INSTALLED_APP_FILE" "$AUTOSTART_FILE"
43+
44+
exit "$?"
45+
fi

0 commit comments

Comments
 (0)