Skip to content

Commit

Permalink
Added main script, license, and readme
Browse files Browse the repository at this point in the history
  • Loading branch information
hngenc committed Aug 11, 2015
0 parents commit c2c9ce7
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 0 deletions.
78 changes: 78 additions & 0 deletions Create Launcher
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#!/bin/bash
#
# Create Launcher 0.1
# A simple Nautilus script to create Unity launchers by right-clicking on files
#
# by Hasan N. Genc

file="$NAUTILUS_SCRIPT_SELECTED_FILE_PATHS"
file=${file%$'\n'}

# Make sure only one file has been selected
if [[ $(printf "$file" | wc -l) > 0 ]]; then
zenity --error --text="Do not select more than one file."
exit 1
fi

# Make sure that selected file is an executable
if ! [[ -x $file ]]; then
zenity --error --text="You must select a file which can be executed."
exit 1
fi

# Get the launcher's name
launcher_name=$(zenity --entry --title="Enter launcher name" --text="Enter name of launcher" --entry-text "${file##*/}" --cancel-label=Quit --width=300)

if [[ $? != 0 ]]; then
exit 1
fi

# Get the launcher's exec command
launcher_exec=$(zenity --entry --title="Enter command" --text="Enter command to be executed by launcher" --entry-text "\"$file\"" --cancel-label=Quit --width=500)

if [[ $? != 0 ]]; then
exit 1
fi

# Get the launcher's icon
if zenity --question --text="Do you want to give the launcher a specific icon?"; then
launcher_icon=$(zenity --file-selection --title="Select icon (cancel if you want to use default icon)")
fi

# Create the launcher file using the previously obtained information
destination="$launcher_name.desktop"
printf "[Desktop Entry]\nType=Application\nTerminal=false\nName=$launcher_name\nExec=$launcher_exec\nIcon=$launcher_icon" >"$destination"

# 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
if [[ $? != 0 ]]; then
zenity --error --text="The launcher cannot be saved in your current directory. Please select a new location to save the launcher."

destination=$(zenity --file-selection --title="Select where to save launcher" --save --confirm-overwrite --file-filter="All files | *.*" --file-filter="Desktop files (.desktop) | *.desktop" )

if [[ $? != 0 ]]; then
exit 1
fi

if [[ $destination != *.desktop ]]; then
destination="$destination.desktop"
fi
fi

until printf "[Desktop Entry]\nType=Application\nTerminal=false\nName=$launcher_name\nExec=$launcher_exec\nIcon=$launcher_icon" >"$destination"; do
zenity --error --text="The launcher cannot be saved in this directory. Please select a new location to save the launcher."

destination=$(zenity --file-selection --title="Select where to save launcher" --save --confirm-overwrite --file-filter="All files | *.*" --file-filter="Desktop files (.desktop) | *.desktop" )

if [[ $? != 0 ]]; then
exit 1
fi

if [[ $destination != *.desktop ]]; then
destination="$destination.desktop"
fi
done

# Make the launcher executable
chmod +x "$destination"

exit 0
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2015 Hasan Nazim Genc

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
18 changes: 18 additions & 0 deletions README
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

Create Launcher 0.1

by Hasan N. Genc

======================
OVERVIEW
======================

"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.

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.

======================
DEPENDENCIES
======================

The only dependency is Zenity, which is installed by default on Ubuntu releases anyway.

0 comments on commit c2c9ce7

Please sign in to comment.