Views:
2,311
Votes: 4
Tags:
command-line
scripts
filemanager
sh
csh
Link:
🔍 See Original Answer on Ask Ubuntu ⧉ 🔗
URL:
https://askubuntu.com/q/1031914
Title:
How to integrate "run as shell script" in right click menu of file manager?
ID:
/2018/05/04/How-to-integrate-_run-as-shell-script_-in-right-click-menu-of-file-manager_
Created:
May 4, 2018
Upload:
September 15, 2024
Layout: post
TOC:
false
Navigation: false
Copy to clipboard: false
Right click to run script in Nautilus
Here is how I setup this script: Nautilus can set desktop wallpaper. How can it set login and lock screen wallpaper?.
After using Nautilus to navigate and view an appropriate .png or .jpg file to use as login screen and lock screen wallpaper, Nautilus can set this for you using a script.
To create the script use:
cd ~/.local/share/nautilus/scripts/
gedit set-login-wallpaper
Paste in these lines:
#!/bin/bash
## Set login wallpaper
# 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 [ -f "${FILENAME}" ]; then
: # Bash noop
else
zenity --error --text "${FILENAME} is not a file!";
exit 2
fi
fi
# Build working file in /tmp
echo "[com.canonical.unity-greeter]" > /tmp/set-login-wallpaper.tmp
echo "draw-user-backgrounds=false" >> /tmp/set-login-wallpaper.tmp
echo "background='$FILENAME'" >> /tmp/set-login-wallpaper.tmp
# Must run as sudo
if [ "$EUID" -ne 0 ] ; then
# Get sudo password
PASSWORD=$(zenity --password --title="Set Login Wallpaper" --timeout=20)
# copy working file to real file using sudo
echo $PASSWORD | sudo -S cp /tmp/set-login-wallpaper.tmp \
/usr/share/glib-2.0/schemas/10_unity_greeter_background.gschema.override
# compile using sudo
echo $PASSWORD | sudo -S glib-compile-schemas /usr/share/glib-2.0/schemas
else
# Already sudo so simply copy and compile
# copy working file to real file
cp /tmp/set-login-wallpaper.tmp \
/usr/share/glib-2.0/schemas/10_unity_greeter_background.gschema.override
# compile
glib-compile-schemas /usr/share/glib-2.0/schemas
fi
exit 0
Save the file and exit the gedit
editor.
Now mark the script as executable using:
chmod +x set-login-wallpaper
Open Nautilus and navigate to your directory with wallpaper images. Find an appropriate image and right-click on it. This drop-down menu appears:
Click on the third option Scripts
. Another drop down menu appears with all your scripts:
Select set-login-wallpaper
.
When the script runs you will have to enter your sudo
password.
Reboot and enjoy your new login and lock screen wallpaper.