Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions create-link-desktop@DopeyDave/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
### 1.0

* Initial Release
21 changes: 21 additions & 0 deletions create-link-desktop@DopeyDave/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Create a Link on the Desktop
========================

Description
-----------

This Action adds the ability to create a link on the Desktop of a file or folder. The link is created using the .desktop file type, which allows for proper path tracking and display on the Desktop.

The behavior is similar to the Windows "create a shortcut" / "send to desktop" functionality.

Shortcuts made of hidden files/folders (filename prepended with ".") will be visible on the Desktop. Normally in Cinnamon, hidden files/folders do not display on the Desktop. Although you can enable the "show hidden files" option in Nemo, this only affects Nemo, and does not affect the Desktop display. But by using .desktop shortcut files, this can allow them to appear. This Action takes the existing filename and alters it so Cinnamon does not consider it a hidden item ("_" is prepended). It then keeps the .desktop "Name" attribute true to the file/folder's actual name, since this is the filename that is actually used for display (this is true for Nemo in a folder view as well as Cinnamon on the Desktop).

This following Actions should be paired for a complete package:
* create-link-desktop@DopeyDave (You Are Here)
* create-link-here@DopeyDave
* follow-desktop-link@DopeyDave

Usage
-----------

Right click on a file or folder. Select the new option "Create Link on Desktop".
7 changes: 7 additions & 0 deletions create-link-desktop@DopeyDave/[email protected]_action.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[Nemo Action]
_Name=Create Link on Desktop
_Comment=For the selected file/folder, create a link (.desktop file) on the Desktop
Exec=<create-link-desktop@DopeyDave/[email protected] "%F">
Icon-Name=emblem-symbolic-link
Selection=notnone
Extensions=any;
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#!/bin/bash

# Check if any files/folders are selected
if [ -z "$1" ]; then
echo "No file/folder selected."
exit 1
fi

# Get the target file or folder
TARGET="$1"

# Debug note:
# To print to the system log (file: /var/log/syslog),
# in bash, use the following example:
# logger "Target: $TARGET"

# If "\" char is in the string
# Note: Use [[double brackets]]
if [[ "$TARGET" == *\\* ]]; then
# Remove all ("//") "\" chars
TARGET="${TARGET//\\}"
fi

# Extract the filename and path
FILENAME=$(basename "$TARGET")
DIRNAME=$(dirname "$TARGET")

# Preserve the real filename, which could start with "." (hidden)
NAME_OF_FILE=$FILENAME

# If the filename starts with a dot, prepend an underscore to the filename
# in order to make it visible on the Desktop
if [[ "$FILENAME" == .* ]]; then
FILENAME="_$FILENAME"
fi

# Get the path to the Desktop folder
DESKTOP_DIR="$HOME/Desktop"

# Check if the Desktop folder exists
if [ ! -d "$DESKTOP_DIR" ]; then
echo "Desktop folder not found."
exit 1
fi

# Create the .desktop file on the Desktop
# Note: If hidden ("."), "_" is pre-pended so file will be visible on the Desktop
DESKTOP_FILE="${DESKTOP_DIR}/${FILENAME}.desktop"

# Check if the .desktop file already exists on the Desktop
if [ -e "$DESKTOP_FILE" ]; then
echo "A .desktop file already exists for this item on the Desktop."
exit 1
fi

# Determine the icon based on the type of file or folder
if [ -d "$TARGET" ]; then
ICON="folder"
elif file --mime-type "$TARGET" | grep -q 'text/'; then
ICON="text"
elif file --mime-type "$TARGET" | grep -q 'application/pdf'; then
ICON="application-pdf"
elif file --mime-type "$TARGET" | grep -q 'image/'; then
ICON="image-x-generic"
elif file --mime-type "$TARGET" | grep -q 'audio/'; then
ICON="audio-x-generic"
elif file --mime-type "$TARGET" | grep -q 'video/'; then
ICON="video-x-generic"
else # Unknown type
ICON="application-octet-stream"
fi

# Create the .desktop file content
echo "[Desktop Entry]" > "$DESKTOP_FILE"
echo "Name=$NAME_OF_FILE" >> "$DESKTOP_FILE" # Use real name of file (this will show "." files/folders correctly on Desktop)
echo "URL=file://$TARGET" >> "$DESKTOP_FILE" # URL format needed for Link type
echo "Icon=$ICON" >> "$DESKTOP_FILE"
echo "Terminal=false" >> "$DESKTOP_FILE"
echo "Type=Link" >> "$DESKTOP_FILE" # Type needs to be Link

# Make the .desktop file executable
chmod +x "$DESKTOP_FILE"

# Output complete
echo "Created .desktop link on the Desktop: $DESKTOP_FILE"
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"description": "Create a link (shortcut) on the Desktop for a file/folder",
"uuid": "create-link-desktop@DopeyDave",
"name": "Create Link on the Desktop",
"author": "DopeyDave",
"version": "1.0"
}
3 changes: 3 additions & 0 deletions create-link-desktop@DopeyDave/info.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"author": "DopeyDave"
}