Skip to content

Commit c2c9ce7

Browse files
committed
Added main script, license, and readme
0 parents  commit c2c9ce7

File tree

3 files changed

+117
-0
lines changed

3 files changed

+117
-0
lines changed

Create Launcher

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
#!/bin/bash
2+
#
3+
# Create Launcher 0.1
4+
# A simple Nautilus script to create Unity launchers by right-clicking on files
5+
#
6+
# by Hasan N. Genc
7+
8+
file="$NAUTILUS_SCRIPT_SELECTED_FILE_PATHS"
9+
file=${file%$'\n'}
10+
11+
# Make sure only one file has been selected
12+
if [[ $(printf "$file" | wc -l) > 0 ]]; then
13+
zenity --error --text="Do not select more than one file."
14+
exit 1
15+
fi
16+
17+
# Make sure that selected file is an executable
18+
if ! [[ -x $file ]]; then
19+
zenity --error --text="You must select a file which can be executed."
20+
exit 1
21+
fi
22+
23+
# Get the launcher's name
24+
launcher_name=$(zenity --entry --title="Enter launcher name" --text="Enter name of launcher" --entry-text "${file##*/}" --cancel-label=Quit --width=300)
25+
26+
if [[ $? != 0 ]]; then
27+
exit 1
28+
fi
29+
30+
# Get the launcher's exec command
31+
launcher_exec=$(zenity --entry --title="Enter command" --text="Enter command to be executed by launcher" --entry-text "\"$file\"" --cancel-label=Quit --width=500)
32+
33+
if [[ $? != 0 ]]; then
34+
exit 1
35+
fi
36+
37+
# Get the launcher's icon
38+
if zenity --question --text="Do you want to give the launcher a specific icon?"; then
39+
launcher_icon=$(zenity --file-selection --title="Select icon (cancel if you want to use default icon)")
40+
fi
41+
42+
# Create the launcher file using the previously obtained information
43+
destination="$launcher_name.desktop"
44+
printf "[Desktop Entry]\nType=Application\nTerminal=false\nName=$launcher_name\nExec=$launcher_exec\nIcon=$launcher_icon" >"$destination"
45+
46+
# If the script tries to create the launcher in a folder that it does not have permission to do so, the previous printf command will fail. In that case, let the user choose where to save the launcher
47+
if [[ $? != 0 ]]; then
48+
zenity --error --text="The launcher cannot be saved in your current directory. Please select a new location to save the launcher."
49+
50+
destination=$(zenity --file-selection --title="Select where to save launcher" --save --confirm-overwrite --file-filter="All files | *.*" --file-filter="Desktop files (.desktop) | *.desktop" )
51+
52+
if [[ $? != 0 ]]; then
53+
exit 1
54+
fi
55+
56+
if [[ $destination != *.desktop ]]; then
57+
destination="$destination.desktop"
58+
fi
59+
fi
60+
61+
until printf "[Desktop Entry]\nType=Application\nTerminal=false\nName=$launcher_name\nExec=$launcher_exec\nIcon=$launcher_icon" >"$destination"; do
62+
zenity --error --text="The launcher cannot be saved in this directory. Please select a new location to save the launcher."
63+
64+
destination=$(zenity --file-selection --title="Select where to save launcher" --save --confirm-overwrite --file-filter="All files | *.*" --file-filter="Desktop files (.desktop) | *.desktop" )
65+
66+
if [[ $? != 0 ]]; then
67+
exit 1
68+
fi
69+
70+
if [[ $destination != *.desktop ]]; then
71+
destination="$destination.desktop"
72+
fi
73+
done
74+
75+
# Make the launcher executable
76+
chmod +x "$destination"
77+
78+
exit 0

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2015 Hasan Nazim Genc
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
2+
Create Launcher 0.1
3+
4+
by Hasan N. Genc
5+
6+
======================
7+
OVERVIEW
8+
======================
9+
10+
"Create Launcher" is a simple Nautilus script used to create Unity launchers (.desktop files) by right-clicking on executable files. Currently, the script only works for non-terminal applications.
11+
12+
To set up the script, copy the "Create Launcher" file to your Nautilus scripts directory (~/.local/share/nautilus/scripts/ for Ubuntu 14.04 and later). Give the script permission to be executed. Finally, make sure to visit the script directory with Nautilus so that your new script will appear on the context menu whenever you right-click a file.
13+
14+
======================
15+
DEPENDENCIES
16+
======================
17+
18+
The only dependency is Zenity, which is installed by default on Ubuntu releases anyway.

0 commit comments

Comments
 (0)