-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_launcher_icons.sh
More file actions
87 lines (72 loc) · 2.78 KB
/
create_launcher_icons.sh
File metadata and controls
87 lines (72 loc) · 2.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/bin/bash
# Version 1.3
# Author: Taylor Flatt
# A script that adds the icons to the launcher for the user running this script.
#
# Note: This script cannot be run as sudo or it will not properly set the icons.
#
# Usage: ./create_launcher_icons.sh
# NOTE: This MUST be changed if launcher_desktop directory is moved. Otherwise, this will not work.
localLauncherDir="/usr/share/appbash_pinnable/launcher_desktop" # Local launcher directory for *.desktop.
# Font colors for error messages.
RED=`tput setaf 1`
END_COLOR=`tput sgr0`
function print_usage()
{
escalated=$1
echo ""
echo "Usage: $0 "; echo ""
if [[ $escalated -eq 1 ]]; then
echo "${RED}This program cannot be run as sudo.${END_COLOR}"
echo "That would result in the icons not being set for this user properly."
echo "Please run as non-sudo"
else
cwd=$(pwd)
echo "${RED}This program doesn't take any parameter inputs.${END_COLOR}"
echo "It simply sets the launcher icons for all *.desktop files located in"
echo "directory: ${cwd}/launcher_desktop"
fi
echo ""
}
# No parameters accepted and the user must not run this as an escalated user.
if [[ $# -ne 0 ]]; then
print_usage 0
exit 1
elif [[ $EUID -eq 0 ]] || [[ -n $SUDO_USER ]]; then
print_usage 1
exit 1;
fi
# Declare the array.
declare -a launcherIcons # Will contain the *.desktop(s) without paths.
# For every file (with *.desktop) in the specical directory
if [[ -d $localLauncherDir ]]; then
for file in $localLauncherDir/*; do
if [[ ! -d "$file" && "$file" = *".desktop" ]]; then
# This returns just the name without the "special/" dir attached.
# Remove everything before file.desktop relative/path/to/file.desktop
launcherIcons+=("${file##*/}")
fi
done
else
echo ""
echo "${RED}Could not find ${localLauncherDir}.${END_COLOR}"
echo "Please make sure this directory exists in the same directory as this script!"
echo ""
fi
# For each launcher *.desktop in $localLauncherDir/, add it to the launcher list.
for ((index=0; index < ${#launcherIcons[@]}; index++)); do
fileName=${launcherIcons[$index]}
# Retrieve ['application://ubiquity.desktop', ..., 'application://firefox.desktop']
currentFavorites=$(gsettings get com.canonical.Unity.Launcher favorites)
# If the file isn't current in the list of launcher icons, add it.
if [[ ${currentFavorites} != *"$fileName"* ]]; then
newFavorites=$(echo $currentFavorites | sed s/]/", 'application:\/\/${fileName}']"/)
gsettings set com.canonical.Unity.Launcher favorites "${newFavorites}"
echo "Adding ${fileName} to the list of launcher favorites."
fi
done
# Note: If a user were to ever mess up their gsettings for com.canonical.Unity.Launcher favorites
# The settings can be reset (Ubuntu 16.04) with the following bash command:
# $ gsettings reset com.canonical.Unity.Launcher favorites
exit 0
#EOF