#!/bin/sh print_help() { echo "Usage: $program_name INPUT-FILE [OPTION]... " echo echo "Changes your current wallpaper" echo "Please note that this script is made to be used with the Atlas Desktop and will probably not work on most other desktops." echo echo "OPTIONS:" echo " -l also apply wallpaper to lockscreen" echo } # Handle arguments ## Default options program_name="$0" input_file="$1" opt_l=false ## No args if [ $# -lt 1 ]; then print_help exit 1 fi ## Parse args shift 1 for arg in "$@"; do case "$arg" in "-l") opt_l=true ;; *) print_help exit 2 ;; esac done # Check if file exists if [ -e "$input_file" ]; then # Variables declaration wallpaper_config=~/.config/hypr/hyprpaper.conf lockscreen_config=~/.config/hypr/hyprlock.conf wallpaper_path=~/.config/hypr/images/wallpaper # Doesn't contain file extension file_extension="${input_file##*.}" # In case file has no extension if [ "${file_extension}" == "$input_file" ]; then echo "Error: please provide a file extension (ex: .jpg, .png...)" exit 1 fi # Remove old wallpaper rm $wallpaper_path* # Copy file cp "$input_file" "${wallpaper_path}.${file_extension}" if [ $? != 0 ]; then echo "Aborted." exit 1 fi # Update config ## Wallpaper sed -i "s/wallpaper\.[^[:space:]]*/wallpaper.$file_extension/g" $wallpaper_config # Replace current extension by new extension if [ $? != 0 ]; then echo "Aborted." exit 1 else echo "Changed wallpaper !" fi ## Lockscreen if [ "$opt_l" == true ]; then sed -i "s/wallpaper\.[^[:space:]]*/wallpaper.$file_extension/g" $lockscreen_config # Replace current extension by new extension if [ $? != 0 ]; then echo "Aborted." echo "Note: Previous actions have not been undone" exit 1 else echo "Changed lockscreen !" fi fi # Reload Hyprpaper pkill hyprpaper hyprctl dispatch exec hyprpaper > /dev/null # Start hyprpaper and hide stdout output # Or you can do the old fashioned way : # nohup hyprpaper /dev/null 2>&1 & echo "Done" exit 0 else echo "Couldn't find '${input_file}': No such file or directory" exit 1 fi