Skip to content

Instantly share code, notes, and snippets.

@okhlybov
Created August 26, 2019 15:25
Show Gist options
  • Select an option

  • Save okhlybov/31b2a1ce03e7b12a5729ce8a661cf12b to your computer and use it in GitHub Desktop.

Select an option

Save okhlybov/31b2a1ce03e7b12a5729ce8a661cf12b to your computer and use it in GitHub Desktop.
GNOME & friends' file manager script to create .desktop entry for arbitrary executable
#!/bin/bash
# File manager -specific file locations
#
# - GNOME3 (Nautilus): ~/.local/share/nautilus/scripts
# - Cinnamon (Nemo): ~/.local/share/nemo/scripts
# - MATE (Caja): ~/.config/caja/scripts
# Note that this file must be marked as executable with `chmod +x file_name`
apps=~/.local/share/applications
IFS=$'\n'
sels=($NAUTILUS_SCRIPT_SELECTED_FILE_PATHS $NEMO_SCRIPT_SELECTED_FILE_PATHS $CAJA_SCRIPT_SELECTED_FILE_PATHS) # Only one will be set anyway
unset IFS
if [[ ${#sels[@]} -ne 1 ]]; then
zenity --error --text="Single selected entry expected"
exit 1
fi
file=${sels[0]}
if [[ ! -x "$file" || -d "$file" ]]; then
zenity --error --text="$file : not an existing executable file"
exit 1
fi
name=`basename $file`
fixed_name=`zenity --entry --title="Create .desktop entry" --text="Set title for new entry" --entry-text="$name"`
if [[ -z "$fixed_name" ]]; then
exit 1
fi
echo "[Desktop Entry]
Type=Application
Name=$fixed_name
StartupNotify=true
Exec=\"$file\"
" > $apps/$name.desktop
zenity --notification --text="Desktop entry for $fixed_name created successfully"
#
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment