Skip to content

Instantly share code, notes, and snippets.

@hilbix
Created May 25, 2014 09:31
Show Gist options
  • Save hilbix/f468fcbb15c3f68670d8 to your computer and use it in GitHub Desktop.
Save hilbix/f468fcbb15c3f68670d8 to your computer and use it in GitHub Desktop.
Wrapper around desktop-file-install to edit Ubuntu launchers (`.desktop` files aka shortcuts)
#!/bin/bash
LOC="$HOME/.local/share/applications"
OOPS()
{
echo "OOPS: $*" >&2
exit 1
}
edit()
{
f="$1"
case "$f" in
*..*) OOPS "illegal path: $1";;
*/applications/*/*) OOPS "wrong path: $1";;
*/applications/*) ;;
*/*) OOPS "wrong path: $1";;
*) f="$LOC/${f%.desktop}.desktop"; [ -s "$f" ] || { ls -al "$LOC" >&2; OOPS "not found: $1"; };;
esac
[ -s "$f" ] || OOPS "unknown: $1"
TMP="$(mktemp -d)"
n="$TMP/${f##*/}"
cp -f "$f" "$n"
while vim "$n"
echo "$?: $n"
desktop-file-install --delete-original --dir="`dirname "$f"`" "$n"
rmdir "$TMP" && return
read
do
:
done
}
edit "$1"
@hilbix
Copy link
Author

hilbix commented May 25, 2014

Thanks to http://askubuntu.com/a/447703 and desktop-file-install the changes update immediately in Compiz.

BUGs:

  • Rough write. Beware! The target .desktop file is deleted before install of the new one. If the new one contains errors, the previous version vanishes unseen. You will find it in the /tmp/ directory somewhere (but /tmp/ is meant to be erased on reboots!) in such a case. This is a design flaw.
  • This script loops (just press return after reading the messages) until all errors in the .desktop file are fixed. If you want to break the loop, press ^D (EOF) after leaving the editor, but this will kill the original .desktop file, see previous point.

Missing features:

  • Create a launcher from scratch
  • Remove a launcher (from the Ubuntu-launcher as well)

License:

How to add such a .desktop file to the Ubuntu launcher if it is missing:

  • Give it a easy to find name
  • Type the name in Dash
  • Select it from there
  • Lock it to launcher

How to use this:

  • Just run the scripts to see a list of your own launchers
  • Then give the basename of your own launcher (or the full path) to this script
  • Edit it - this uses vim. If you like another editor, replace this. Perhaps replace vim in the script with editor.
  • You probably can edit /usr/share/applications/*.desktop files if you run it sudo (never been tested!), but you shouldn't.
  • Instead, copy them to ~/.local/share/applications/ first and edit them there. But this, again, has not been tested.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment