-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdesktop_synch.sh
115 lines (75 loc) · 2.45 KB
/
desktop_synch.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#!/bin/bash
#desktop wallpaper icon synch between linux and windows xp
#useful functions
function find_wallpaper () {
# save it
OLDIFS="$IFS"
# don't split on any white space
IFS=""
vms[0]=$1
tmp=$(echo "${vms[0]}")
#get the right image
PIC=$(ls "$tmp" -R | grep -E '(png|jpg)$' | sort -R | tail -1)
#search for folder
fullpath=$(find "$tmp" -name "$PIC")
export DIR=${fullpath%/*};
# restore IFS # first select random image recursively
IFS=$OLDIFS
# save result
file="$DIR/$PIC"
eval 'file=$file'
}
function copyfile() {
#check if wallpaper.jpg and wallpaper.png exist
#create blank temporary file first
#> "$2"
#echo "$1"
#https://stackoverflow.com/questions/20936531/error-cp-cannot-create-regular-file-no-such-file-or-directory
cp "$1" "$2"
#chmod 644 "$2"
}
function copy_dropbox() {
#get the file extension
file="$1"
filename=$(basename "$1")
extension="${filename##*.}"
#check if dropbox folder exists
if [ -d "$HOME/Dropbox" ]; then
#check if Desktop Folder exists
if [ ! -d "$HOME/Dropbox/Desktop" ]; then
#create this folder then
mkdir "$HOME/Dropbox/Desktop"
fi
#erase contents of dropbox/desktop folder
rm -rf $HOME/Dropbox/Desktop/*
#copy the file to the dropbox wallpaper folder
copyfile "$file" "$HOME/Dropbox/Desktop/wallpaper.$extension"
#https://stackoverflow.com/questions/592620/how-to-check-if-a-program-exists-from-a-bash-script
#check if imagemagick is installed
if hash convert 2>/dev/null; then
#convert the file in here to a bmp
convert "$HOME/Dropbox/Desktop/wallpaper.$extension" "$HOME/Dropbox/Desktop/wallpaper.bmp"
#erase the old file
rm -rf "$HOME/Dropbox/Desktop/wallpaper.$extension"
fi
fi
}
function change_wallpaper() {
#get the file
file="$1"
#change wall paper for gnome2
/usr/bin/gconftool-2 --type string --set /desktop/gnome/background/picture_filename "$file"
#change wallpaper for gnome3
gsettings set org.gnome.desktop.background picture-uri "file://$file"
gsettings set org.gnome.desktop.background picture-options "stretched"
}
# Directory Containing Pictures
DIR="/media/Backup/My Wallpapers"
file=''
#step 1. given a folder, select one random image from a given specific folder
find_wallpaper "$DIR";
#step 2. change wallpaper accordingly
change_wallpaper "$file";
#step 3. copy the wallpaper image file to /dropbox/desktop/wallpaper.png
copy_dropbox "$file";
#step 4. extract ico files from linux desktop to /dropbox/desktop/*.ico