-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdtg.sh
executable file
·80 lines (64 loc) · 2.36 KB
/
dtg.sh
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
#!/usr/bin/env bash
## Show input to user to write the theme name
while [ ! "$themeName" ]
do
themeName=$(kdialog --title "Dynamic Theme Generator - Theme name" --inputbox "What name would you like to use?" "DynamicTheme")
if [ ! "$themeName" ]; then
kdialog --error "Name should not be empty!"
fi
done
## Show input to user to write the theme author
while [ ! "$themeAuthor" ]
do
themeAuthor=$(kdialog --title "Dynamic Theme Generator - Theme author" --inputbox "What name would you like to use?" "DynamicTheme")
if [ ! "$themeName" ]; then
kdialog --error "Name should not be empty!"
fi
done
themeID="${themeName// /}"
wallpaperPath="$HOME/.local/share/wallpapers/$themeID"
## Select images and store it to variables
l_path=$(kdialog --title "Dynamic Theme Generator - Light Image" --getopenfilename "$HOME" '*')
l_ext="${l_path##*.}"
d_path=$(kdialog --title "Dynamic Theme Generator - Dark Image" --getopenfilename "$HOME" '*')
d_ext="${d_path##*.}"
## Get image sizes
l_width=$(identify -format "%w" "$l_path")> /dev/null
l_height=$(identify -format "%h" "$l_path")> /dev/null
d_width=$(identify -format "%w" "$d_path")> /dev/null
d_height=$(identify -format "%h" "$d_path")> /dev/null
## Show progressbar - First step
dbusRef=$(kdialog --title "Dynamic Theme Generator - Generating Files" --progressbar "Generating the metadata file" 3)
qdbus $dbusRef Set "" value 1
## Create Metadata file
mkdir -p "$wallpaperPath"
## Write in Metadata file
cat << EOF > "$wallpaperPath/metadata.json"
{
"KPlugin": {
"Authors": [
{
"Name": "$themeAuthor"
}
],
"Id": "$themeID",
"Name": "$themeName"
}
}
EOF
## Show progressbar - light image
qdbus $dbusRef setLabelText "Creating folders and copying the light image"
qdbus $dbusRef Set "" value 2
l_folder="$wallpaperPath/contents/images"
mkdir -p "$l_folder"
cp "$l_path" "$l_folder/${l_width}x${l_height}.$l_ext"
## Show progressbar - dark image
qdbus $dbusRef setLabelText "Creating folders and copying the dark image"
qdbus $dbusRef Set "" value 3
d_folder="$wallpaperPath/contents/images_dark"
mkdir -p "$d_folder"
cp "$d_path" "$d_folder/${d_width}x${d_height}.$d_ext"
## Close progressbar
qdbus $dbusRef close
### Final message
kdialog --title "Dynamic Theme Generator - Final" --msgbox "The wallpaper was successfully generated."