Send to Desktop – Create Symlink

Having set up automatic incremental backups for my home directory, I need to follow some simple rules in order not to poison the backups with temporary files (sometimes huge ones) I usually place on my desktop for later viewing. One of those rules is to stop downloading stuff directly to the desktop, but use a dedicated directory for that purpose, for instance ~/Download, which is excluded from the automatic backups. Since the downloads directory is usually a mess, I needed a quick way to create one or more symbolic links on my desktop pointing to files inside Downloads/. The normal approach would have been to create a Nautilus Action, but it seems that this tool is not very efficient since it has issues with paths that contain spaces. If quotes are used in order to make “paths with spaces” work, it still cannot successfully create the symbolic link. So, I decided to write a small shell script that can create symbolic links on the desktop for the selected files or directories. It supports paths containing spaces and also multi-selection of items (files/dirs) and will warn you before creating multiple symlinks.

#! /usr/bin/env bash
#
#  Send to Desktop - Create Symlink
#
#  Project: http://www.g-loaded.eu/2008/11/03/send-to-desktop-create-symlink/
#
#  Features:
#      - creates symlinks on the desktop pointing to each of the selected items
#        (files/directories).
#      - Supports paths containing spaces.
#      - Supports multi-selection (warns before creating multiple symlinks)
#
#  Requires:
#      - ln
#      - zenity
#
#  Installation:
#  1) Put the file in ~/.gnome2/nautilus-scripts/
#       cp "Send to Desktop - Create Symlink" ~/.gnome2/nautilus-scripts/
#  2) Set the 'executable' bit:
#       chmod -x ~/.gnome2/nautilus-scripts/"Send to Desktop - Create Symlink"
#  3) Access the script by right clicking and selecting the submenu 'scripts'
#
#  Copyright 2008 George Notaras <gnot [at] g-loaded.eu>, CodeTRAX.org
#
#  Licensed under the Apache License, Version 2.0 (the "License");
#  you may not use this file except in compliance with the License.
#  You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
#  Unless required by applicable law or agreed to in writing, software
#  distributed under the License is distributed on an "AS IS" BASIS,
#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#  See the License for the specific language governing permissions and
#  limitations under the License.
#
 
DESKTOP=~/Desktop
 
if [ $# -lt 1 ] ; then
  zenity --error --text "At least one file or directory must be selected."
elif [ $# -gt 1 ] ; then
  zenity --question --text "Multiple items selected. Proceed?"
fi
 
if [ "$?" = 1 ] ; then
    exit 1
fi
 
for item in "$@"; do
    ln -s "$PWD/$item" "$DESKTOP/$(basename $item)"
done
 
exit 0

Save the code in a file. Assuming that you have saved it as “Send to Desktop – Create Symlink“, follow the instructions below in order to install and use it:

1 — Put the file in ~/.gnome2/nautilus-scripts/

cp "Send to Desktop - Create Symlink" ~/.gnome2/nautilus-scripts/

2 — Set the ‘executable‘ bit:

chmod +x ~/.gnome2/nautilus-scripts/"Send to Desktop - Create Symlink"

3 — Access the script by right clicking and selecting the submenu ‘scripts

Enjoy!

Send to Desktop – Create Symlink by George Notaras is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
Copyright © 2008 - Some Rights Reserved

One response on “Send to Desktop – Create Symlink