Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to copy wallpaper to a file instead of setting the wallpaper #61

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
272 changes: 37 additions & 235 deletions README.md

Large diffs are not rendered by default.

114 changes: 92 additions & 22 deletions dwall.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/usr/bin/env bash

## Author : Aditya Shakya (adi1090x)
## Mail : [email protected]
## Github : @adi1090x
## Twitter : @adi1090x
## Author : Aditya Shakya (adi1090x), GitGangGuy
## Mail : [email protected], -
## Github : @adi1090x, @GitGangGuy
## Twitter : @adi1090x, -

## Dynamic Wallpaper : Set wallpapers according to current time.
## Created to work better with job schedulers (cron)
Expand Down Expand Up @@ -44,7 +44,7 @@ trap exit_on_signal_SIGTERM SIGTERM

## Prerequisite
Prerequisite() {
dependencies=(feh xrandr crontab)
dependencies=(feh xrandr crontab xargs)
for dependency in "${dependencies[@]}"; do
type -p "$dependency" &>/dev/null || {
echo -e ${RED}"[!] ERROR: Could not find ${GREEN}'${dependency}'${RED}, is it installed?" >&2
Expand All @@ -59,18 +59,22 @@ usage() {
cat <<- EOF
${RED}╺┳┓╻ ╻┏┓╻┏━┓┏┳┓╻┏━╸ ${GREEN}╻ ╻┏━┓╻ ╻ ┏━┓┏━┓┏━┓┏━╸┏━┓
${RED} ┃┃┗┳┛┃┗┫┣━┫┃┃┃┃┃ ${GREEN}┃╻┃┣━┫┃ ┃ ┣━┛┣━┫┣━┛┣╸ ┣┳┛
${RED}╺┻┛ ╹ ╹ ╹╹ ╹╹ ╹╹┗━╸ ${GREEN}┗┻┛╹ ╹┗━╸┗━╸╹ ╹ ╹╹ ┗━╸╹┗╸${WHITE}
${RED}╺┻┛ ╹ ╹ ╹╹ ╹╹ ╹╹┗━╸ ${GREEN}┗┻┛╹ ╹┗━╸┗━╸╹ ╹ ╹╹ ┗━╸╹┗╸
${CYAN}[ I M P R O V E D ]${WHITE}

Dwall V2.0 : Set wallpapers according to current time.
Developed By : Aditya Shakya (@adi1090x)
Usage : `basename $0` [-h] [-p] [-s style]
A bash script to adapt your wallpaper to the time
By Aditya Shakya (@adi1090x) and GitGangGuy

Usage `basename $0` [ -h ] [ -p [ -b backend ] [ -a | -l ] ] [ -s style ] [ -o output ]

Options:
-h Show this help message
-p Use pywal to set wallpaper
-s Name of the style to apply

-h Show this help message
-p Use pywal to set wallpaper
-b Pass a backend to pywal (optional)
-l Force light color scheme
-a Automatically set light/dark color scheme based on GNOME theme or daytime
-s Name of the style to apply
-o Output wallpaper to file instead of setting it
EOF

styles=(`ls $DIR`)
Expand All @@ -79,10 +83,13 @@ usage() {
printf -- '\n\n'${WHITE}

cat <<- EOF
Examples:
`basename $0` -s beach Set wallpaper from 'beach' style
`basename $0` -p -s sahara Set wallpaper from 'sahara' style using pywal

Examples:
`basename $0` -s beach Set 'beach' style wallpaper
`basename $0` -s beach -o ~/.wallpaper Save 'beach' style wallpaper into file '~/.wallpaper'
`basename $0` -p -s sahara Set 'beach' style wallpaper, and refresh the pywal theme
`basename $0` -p -b colorz -s sahara " with 'colorz' backend
`basename $0` -p -b colorz -s sahara -a " with automatic light/dark mode
`basename $0` -p -b colorz -s sahara -l " with forced light mode
EOF
}

Expand All @@ -106,6 +113,11 @@ set_cinnamon() {
gsettings set org.cinnamon.desktop.background picture-uri "file:///$1"
}

## Set wallpaper in GNOME
set_gnome() {
gsettings set org.gnome.desktop.background picture-uri "file:///$1"
gsettings set org.gnome.desktop.screensaver picture-uri "file:///$1"
}
## For XFCE only
if [[ "$OSTYPE" == "linux"* ]]; then
SCREEN="$(xrandr --listactivemonitors | awk -F ' ' 'END {print $1}' | tr -d \:)"
Expand All @@ -128,7 +140,7 @@ case "$OSTYPE" in
elif [[ "$DESKTOP_SESSION" =~ ^(/usr/share/xsessions/plasma|NEON|Neon|neon|PLASMA|Plasma|plasma|KDE|Kde|kde)$ ]]; then
SETTER=set_kde
elif [[ "$DESKTOP_SESSION" =~ ^(PANTHEON|Pantheon|pantheon|GNOME|Gnome|gnome|Gnome-xorg|gnome-xorg|UBUNTU|Ubuntu|ubuntu|DEEPIN|Deepin|deepin|POP|Pop|pop)$ ]]; then
SETTER="gsettings set org.gnome.desktop.background picture-uri"
SETTER=set_gnome
else
SETTER="feh --bg-fill"
fi
Expand All @@ -150,17 +162,59 @@ get_img() {
fi
}

## Check valid pywal backend
pywal_backend() {
backends=$(wal --backend | tail -n +2 | cut -d ' ' -f 3 | xargs)
[[ "$backends" =~ (^| )"$1"($| ) ]] && return 0 || return 1
}

## Determine light/dark scheme based on GNOME night light or daytime
pywal_light() {
[[ $WALSCHEME == 'light' ]] && return 0
if [[ $WALSCHEME == 'auto' ]]; then
[[ $DESKTOP_SESSION =~ ^(GNOME|Gnome|gnome|Gnome-xorg|gnome-xorg)$ && $(gsettings get org.gnome.desktop.interface gtk-theme) != *"dark"* ]] && return 0
(( $HOUR > 6 && $HOUR < 18 )) && return 0
fi
return 1
}

## Set wallpaper with pywal
pywal_set() {
get_img "$1"
if ! pywal_backend "$2"; then
echo -e ${RED}"[!] $2 is not a valid pywal backend. Check valid backends with `wal --backend`. Exiting..."
{ reset_color; exit 1; }
fi
if [[ -x `command -v wal` ]]; then
wal -i "$image.$FORMAT"
local walcmd=(wal --backend "$2" -i "$image.$FORMAT" -n)
if pywal_light; then
walcmd+=(-l)
fi
"${walcmd[@]}"
set_wallpaper "$1"
else
echo -e ${RED}"[!] pywal is not installed on your system, exiting..."
{ reset_color; exit 1; }
fi
}

## Put wallpaper in $OUTPUT
file_set() {
get_img "$1"
if [[ -n $(echo "$OUTPUT" | grep -o "^[/~]") ]]
then
DIR=$(dirname $OUTPUT)
if [[ -d $DIR ]]
then
cp "$image.$FORMAT" "$OUTPUT"
else
echo "[!] Directory $DIR does not exist, exiting..."
fi
else
echo "[!] Output must be an absolute path, $OUTPUT isn't, exiting..."
fi
}

## Wallpaper Setter
set_wallpaper() {
cfile="$HOME/.cache/dwall_current"
Expand Down Expand Up @@ -205,21 +259,37 @@ main() {
num=$(($HOUR/1))
# set wallpaper accordingly
if [[ -n "$PYWAL" ]]; then
{ pywal_set "$num"; reset_color; exit 0; }
_walbackend=${WALBACKEND:-wal}
{ pywal_set "$num" "$_walbackend"; reset_color; exit 0; }
elif [[ -n "$OUTPUT" ]]; then
{ file_set "$num"; reset_color; exit 0; }
else
{ set_wallpaper "$num"; reset_color; exit 0; }
fi
}

WALSCHEME='dark'
## Get Options
while getopts ":s:hp" opt; do
while getopts ":hplas:b:o:" opt; do
case ${opt} in
p)
PYWAL=true
;;
o)
OUTPUT=$OPTARG
;;
b)
WALBACKEND=$OPTARG
;;
s)
STYLE=$OPTARG
;;
l)
WALSCHEME='light'
;;
a)
WALSCHEME='auto'
;;
h)
{ usage; reset_color; exit 0; }
;;
Expand Down
Binary file added images/bigsur/0.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions images/bigsur/1.jpg
1 change: 1 addition & 0 deletions images/bigsur/10.jpg
1 change: 1 addition & 0 deletions images/bigsur/11.jpg
1 change: 1 addition & 0 deletions images/bigsur/12.jpg
Binary file added images/bigsur/13.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions images/bigsur/14.jpg
1 change: 1 addition & 0 deletions images/bigsur/15.jpg
1 change: 1 addition & 0 deletions images/bigsur/16.jpg
Binary file added images/bigsur/17.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/bigsur/18.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/bigsur/19.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions images/bigsur/2.jpg
1 change: 1 addition & 0 deletions images/bigsur/20.jpg
1 change: 1 addition & 0 deletions images/bigsur/21.jpg
1 change: 1 addition & 0 deletions images/bigsur/22.jpg
1 change: 1 addition & 0 deletions images/bigsur/23.jpg
1 change: 1 addition & 0 deletions images/bigsur/3.jpg
1 change: 1 addition & 0 deletions images/bigsur/4.jpg
1 change: 1 addition & 0 deletions images/bigsur/5.jpg
Binary file added images/bigsur/6.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/bigsur/7.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/bigsur/8.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions images/bigsur/9.jpg
Loading