-
Notifications
You must be signed in to change notification settings - Fork 2
/
Create Desktop entry
99 lines (76 loc) · 1.83 KB
/
Create Desktop entry
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
#!/bin/bash
source "$HOME/.config/user-dirs.dirs"
#it's important
IFS='
'
generateDesktopEntry() {
EXEC=$1
DESK_TEXT="
[Desktop Entry]
Version=1.0
Type=Application
Encoding=UTF-8
Name=$NAME_WITHOUT_EXT
Exec=$EXEC
Path=$MYDIR
StartupWMClass=$BASENAME"
}
EXECUTABLE=false
checkExecutable(){
if [ ! -z "`file $1 | grep 'executable'`" ]; then
EXECUTABLE=true
else
EXECUTABLE=false
fi
}
ICON_FORMAT_LIST="ico png gif tif jpg jpeg bmp"
ICON=false
checkIcon(){
if [ ! -z "`echo "$ICON_FORMAT_LIST" | grep $1`" ]; then
ICON=true
else
ICON=false
fi
}
EXECUTABLE_FOUND=false
DONE=false
for FILE in $NAUTILUS_SCRIPT_SELECTED_FILE_PATHS
do
MYDIR=`dirname $FILE`
BASENAME=`basename $FILE`
EXT=$(echo $BASENAME | cut -f 2 -d '.')
NAME_WITHOUT_EXT=$(echo $BASENAME | cut -f 1 -d '.')
DESKTOP_FILE=$XDG_DESKTOP_DIR/$BASENAME.desktop
generateDesktopEntry "bash -c './$BASENAME'"
checkExecutable $FILE
checkIcon $EXT
echo "EXECUTABLE $EXECUTABLE"
echo "EXECUTABLE_FOUND $EXECUTABLE_FOUND"
echo "$EXT"
#first executable found and windows .exe
if [ "$EXECUTABLE" == true ] && [ "$EXECUTABLE_FOUND" == false ] && [ "$EXT" == "exe" ]; then
generateDesktopEntry "wine start.exe /Unix ./'$BASENAME'"
#extract icon if not selected
if [ -z $DESK_ICON ]; then
ICONSDIR=$XDG_DESKTOP_DIR/.exeicons
mkdir $XDG_DESKTOP_DIR/.exeicons
#extract .ico
wrestool -t 'group_icon' -o $ICONSDIR/$BASENAME.ico -x $FILE
#convert to png
icotool -x -o $ICONSDIR/$BASENAME.png $ICONSDIR/$BASENAME.ico
DESK_ICON="$ICONSDIR/$BASENAME.png"
fi
elif [ "$ICON" == true ]; then
DESK_ICON=$FILE
fi
if [ "$EXECUTABLE" == true ]; then
EXECUTABLE_FOUND=true
fi
if [ "$EXECUTABLE_FOUND" == true ] && [ ! -z $DESK_ICON ]; then
break
fi
done
DESK_TEXT="$DESK_TEXT
Icon=$DESK_ICON"
echo "$DESK_TEXT" > $DESKTOP_FILE
chmod +x $DESKTOP_FILE