|
1 |
| -#!/bin/bash |
| 1 | +#!/usr/bin/env sh |
2 | 2 |
|
3 |
| -# DESCRIPTION |
| 3 | +# DESCRIPTION |
4 | 4 | # 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. |
6 | 6 | #
|
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 |
9 | 9 | # "mulige" to print a full list of eligible files to add to autostart.
|
10 | 10 | #
|
11 | 11 | # 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. |
15 | 15 | # 2. Checkbox. Check this box to delete a file from the autostart folder instead.
|
16 | 16 |
|
17 |
| -SELECTED=$1 |
18 |
| -DELETE=$2 |
| 17 | +set -x |
19 | 18 |
|
20 |
| -if [[ $SELECTED != *.desktop ]]; then |
21 |
| - SELECTED="$SELECTED.desktop" |
22 |
| -fi |
| 19 | +PROGRAM="$1" |
| 20 | +DELETE="$2" |
23 | 21 |
|
24 | 22 | AUTOSTART_DIR="/home/.skjult/.config/autostart"
|
25 |
| -AUTOSTART_FILE="$AUTOSTART_DIR/$SELECTED" |
26 |
| -INSTALLED_APP_FILE="/usr/share/applications/$SELECTED" |
27 | 23 |
|
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 |
32 | 25 |
|
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" |
34 | 31 | fi
|
35 | 32 |
|
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" |
37 | 37 |
|
38 |
| -echo "Adding $SELECTED to autostart directory" |
| 38 | +if [ "$DELETE" != "True" ]; then |
39 | 39 |
|
40 |
| -cp "$INSTALLED_APP_FILE" "$AUTOSTART_FILE" |
| 40 | + echo "Adding $PROGRAM to autostart directory" |
41 | 41 |
|
42 |
| -exit "$?" |
| 42 | + ln --symbolic --force "$INSTALLED_APP_FILE" "$AUTOSTART_FILE" |
| 43 | + |
| 44 | + exit "$?" |
| 45 | +fi |
0 commit comments