The Cookie Machine - Click here to drag window

DUMMY TEXT - Real text set in assets/js/theCookieMachine.js

Views: 1,962β€…    Votes:  3β€…    βœ… Solution
Tags: gui   filemanager   symbolic-link  
Link: πŸ” See Original Answer on Ask Ubuntu πŸ”—

URL: https://askubuntu.com/q/1066741
Title: How to edit target path of broken symbolic link from GUI?
ID: /2018/08/19/How-to-edit-target-path-of-broken-symbolic-link-from-GUI_
Created: August 19, 2018    Edited:  August 19, 2018
Upload: November 24, 2022    Layout:  post
TOC: false    Navigation:  false    Copy to clipboard:  false


Edit Symbolic Link in Nautilus

The script

To do this in Nautilus we need to create a script using:

mkdir -p ~/.local/share/nautilus/scripts
gedit ~/.local/share/nautilus/scripts/edit-link

Paste in the following:

#!/bin/bash

# NAME: edit-link
# PATH: $HOME/.local/share/nautilus/scripts
# DESC: Edit symbolic link
# CALL: Called from Nautilus file manager.
# DATE: August 18, 2018.

# strip new line char passed by Nautilus
FILENAME=$(echo $NAUTILUS_SCRIPT_SELECTED_FILE_PATHS | sed -e 's/\r//g')

# Multiple files can't be selected.
LINE_COUNT=$(wc -l <<< "$NAUTILUS_SCRIPT_SELECTED_FILE_PATHS")
LINE_COUNT=$((LINE_COUNT-1))

if [[ $LINE_COUNT > 1 ]] ; then
    zenity --error --text "Ony one file can be selected at a time! "
    exit 1
fi

# Object type must be "file..." (ie no directories, etc.)
if [ -d "${FILENAME}" ] ; then
    zenity --error --text "$FILENAME is a directory!";
    exit 1
else
    if [ -L "${FILENAME}" ]; then
        : # Bash noop
    else
        zenity --error --text "${FILENAME} is not a symbolic link!";
        exit 2
    fi
fi

NewLink=$(zenity --entry --text "Enter new symbolic link")
ln -sf "$NewLink" "${FILENAME}"

exit 0

and make it executable

chmod +x ~/.local/share/nautilus/scripts/edit-link

Sample output

This is the test data used. The second last section shows the broken link. Then our script is run giving a new file name. The last section shows the new good link.

[![Edit Link2][1]][1]

Sample screen

This is what the script looks like when you run it:

[![edit link 1.png][2]][2]

Edit Symbolic Link in Caja

The method is similar to Nautilus but with some Caja specifics. We should follow GNOME2β†’MATE Migration guide.

So we need create script in the ~/.config/caja/scripts:

mkdir -p ~/.config/caja/scripts
cat > ~/.config/caja/scripts/edit-link << \EOF
#!/bin/bash

# NAME: edit-link
# PATH: $HOME/.config/caja/scripts
# DESC: Edit symbolic link
# CALL: Called from Caja file manager.
# DATE: August 19, 2018.

# strip new line char passed by Caja
FILENAME=$(echo $CAJA_SCRIPT_SELECTED_FILE_PATHS | sed -e 's/\r//g')

# Multiple files can't be selected.
LINE_COUNT=$(wc -l <<< "$CAJA_SCRIPT_SELECTED_FILE_PATHS")
LINE_COUNT=$((LINE_COUNT-1))

if [[ $LINE_COUNT > 1 ]] ; then
    zenity --error --text "Ony one file can be selected at a time! "
    exit 1
fi

# Object type must be "file..." (ie no directories, etc.)
if [ -d "${FILENAME}" ] ; then
    zenity --error --text "$FILENAME is a directory!";
    exit 1
else
    if [ -L "${FILENAME}" ]; then
        : # Bash noop
    else
        zenity --error --text "${FILENAME} is not a symbolic link!";
        exit 2
    fi
fi

NewLink=$(zenity --entry --text "Enter new symbolic link")
ln -sf "$NewLink" "${FILENAME}"

exit 0
EOF

and make it executable

chmod +x ~/.config/caja/scripts/edit-link

Then we can use this script from Caja Scripts drop-down menu. [1]: https://i.stack.imgur.com/0NmbJ.png [2]: https://i.stack.imgur.com/7ypms.png

⇧ Set LD_LIBRARY_PATH correctly Get all available frequency steps  β‡©