Set wallpaper dir with pcmanfm,
The following script looks first if there are images in the selected dir.
Select a directory with images and set as Wallpaper dir.
Give it a name like : (if you change the name : look also at .desktop)
pcmanfm-mbwallpaper-dir
#!/bin/bash
# Define the config file path
CONFIG_FILE="$HOME/.config/mbwallpaper/mbwallpaper.conf"
# Check if a directory is selected
if [ -z "$1" ]; then
notify-send -u critical "Error" "No directory selected."
exit 1
fi
# Check if the directory contains any images
has_image=0
for file in "$1"/*; do
if [ -f "$file" ]; then
file_type=$(file -b --mime-type "$file")
if [[ "$file_type" == "image/jpeg" || "$file_type" == "image/png" ]]; then
has_image=1
break
fi
fi
done
if [ $has_image -eq 1 ]; then
# Check if the config file exists; if not, create the directory and the file
if [ ! -f "$CONFIG_FILE" ]; then
mkdir -p "$(dirname "$CONFIG_FILE")" # Create the directory if it doesn't exist
touch "$CONFIG_FILE" # Create the config file
notify-send "Config File Created" "Config file created at: $CONFIG_FILE"
fi
# Write the selected directory to the config file, replacing the existing wallpaper_dir value
if grep -q "^wallpaper_dir=" "$CONFIG_FILE"; then
sed -i "s|^wallpaper_dir=.*|wallpaper_dir=\"$1\"|" "$CONFIG_FILE"
else
echo "wallpaper_dir=\"$1\"" >> "$CONFIG_FILE"
fi
notify-send -t 5000 -i wallpaper "Success" "Wallpaper directory has been set to: $1"
else
notify-send -t 5000 -i error "Warning" "No JPG or PNG images detected in: $1. Please select a valid directory."
fi
Create a .desktop
and cp to actions dir.
~/.local/share/file-manager/actions/<name-it>.desktop
or system wide.
/usr/local/share/file-manager/actions/<name-it>.desktop
[Desktop Entry]
Type=Action
Name=Set Wallpaper Dir
Icon=wallpaper
Profiles=profile-setwallpaperdir
[X-Action-Profile profile-setwallpaperdir]
MimeTypes=inode/directory;
Exec=/home/USER/bin/pcmanfm-mbwallpaper-dir %f
Name=Set wallpaper dir
Edit: 2 : corrected path .desktop