Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@nemec
Last active November 29, 2022 18:04
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nemec/5b36fee11980e8f48c7d to your computer and use it in GitHub Desktop.
Save nemec/5b36fee11980e8f48c7d to your computer and use it in GitHub Desktop.
#!/bin/bash
# Place in ~/.local/share/nautilus/scripts and an option will be added to the
# Nautilus context menu to add the selected file(s) as favorites in the Gnome
# overlay.
IFS_BAK=$IFS
IFS="
"
APP_FOLDER=~/.local/share/applications
mkdir -p ~/.cache/
APPS=$(dconf read /org/gnome/shell/favorite-apps)
echo "dconf write /org/gnome/shell/favorite-apps \"$APPS\"" > ~/.cache/favs-script.backup
for line in $NAUTILUS_SCRIPT_SELECTED_FILE_PATHS; do
fname=$(basename $line)
if [[ "$line" = "" || "$line" = " " ]]; then
exit
else
dsk="$fname.desktop"
while [ -f "$APP_FOLDER/$dsk" ]; do
dsk="$fname.$RANDOM.desktop"
done
cat >"$APP_FOLDER/$dsk" <<EOL
[Desktop Entry]
Name=${fname}
Exec=xdg-open "${line}"
Type=Application
Terminal=false
EOL
chmod +x "$APP_FOLDER/$dsk"
new_apps="${APPS::-1}, '$dsk']"
dconf write /org/gnome/shell/favorite-apps "$new_apps"
fi
done
IFS=$IFS_BAK
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment