Skip to content

Commit

Permalink
Changed scripts to work with new unsplash API
Browse files Browse the repository at this point in the history
  • Loading branch information
rodude123 committed Oct 27, 2022
1 parent 1f55f7e commit 9bab913
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 7 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
chosenCat.txt
alreadySaved.txt
saved.txt
clientID.txt
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# wallpaper-changer
This is a set of scripts to change your wallpaper and save it to your pictures directory so that it can be recycled back as one of the pictures.
This is a set of scripts to change your wallpaper and save it to your pictures directory so that it can be recycled back as one of the pictures. Since unsplash is deprecating the open source.unsplash.com api, this script has be updated for the new api. To use the updated script an client ID is required, follow https://unsplash.com/documentation#creating-a-developer-account to get one

## init.sh
This script makes the wallpapers directory in your users pictures folder, then creates the cw and sw scripts which allow you to run them globally.
init.sh takes 2 paramenters the environment, and client ID. So far KDE and nitrogen are supported more will be supported soon. If the init.sh script fails please create the file clientID.txt in the same directory as the scripts to allow you to use the scipts.

## wallpaper.sh
This script randomly chooses to download a wallpaper or chose one from your local list of wallpapers. If downloading a wallper is chosen it will download a wallpaper and set it. If choosing a wallpaper from your local list is chosen then it will try and find a wallpaper in the chosen category's directory, if one doesn't exist it will download one instead and set it.
Expand All @@ -11,4 +12,4 @@ This script randomly chooses to download a wallpaper or chose one from your loca
This script saves the current wallpaper to the chosen category's directory.

## usage
Run `./init.sh` first as you may get errors when saving, or create the wallpapers directory in the pictures directory. You may have to supply a root password for the script to mv the cw and sw scripts into the bin directory.
Run `./init.sh` with the parameters first as you may get errors when saving, or create the wallpapers directory in the pictures directory. You may have to supply a root password for the script to mv the cw and sw scripts into the bin directory.
6 changes: 6 additions & 0 deletions init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@ if [[ $1 == "" ]]; then
exit
fi

if [[ $2 == "" ]]; then
echo "Client ID not supplied, to obtain a client ID visit https://unsplash.com/documentation#creating-a-developer-account"
exit
fi

echo -e "#!/bin/bash\n$PWD/wallpaper.sh $1" > cw
echo -e $2 > clientID.txt
echo -e "#!/bin/bash\n$PWD/saveWallpaper.sh" > sw

chmod +x cw sw
Expand Down
17 changes: 12 additions & 5 deletions wallpaper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,15 @@ categories=()

mapfile -t categories < $path/categories.txt

clientID=$(head -n 1 $path/clientID.txt)

randCat=$((RANDOM % ${#categories[@]}))
chosenCat=${categories[$randCat]}

rm -f $path/chosenCat.txt
rm -f $path/alreadySaved.txt

rm -f $HOME/Pictures/wallpapers/current.png

if [[ $((1 + RANDOM % 100)) -le 50 ]]; then

Expand All @@ -32,28 +35,32 @@ if [[ $((1 + RANDOM % 100)) -le 50 ]]; then
notify-send "Wallpaper doesn't exist so downloaded wallpaper instead"
echo "Wallpaper doesn't exist so downloaded wallpaper instead"
chosenCata=${chosenCat// /%20%}
wget -q "https://source.unsplash.com/3840x2160/?$chosenCata" -O $HOME/Pictures/wallpapers/current.png & > /dev/null
url=$(curl "https://api.unsplash.com/photos/random?query=$chosenCata&orientation=landscape&client_id=$clientID" | jq '. | .urls.raw' | sed 's/"//g')
wget $url -O $HOME/Pictures/wallpapers/current.png & > /dev/null
rm -f $path/saved.txt
fi

else
notify-send "Wallpaper doesn't exist so downloaded wallpaper instead"
echo "Wallpaper doesn't exist so downloaded wallpaper instead"
chosenCata=${chosenCat// /%20%}
wget -q "https://source.unsplash.com/3840x2160/?$chosenCata" -O $HOME/Pictures/wallpapers/current.png & > /dev/null
url=$(curl "https://api.unsplash.com/photos/random?query=$chosenCata&orientation=landscape&client_id=$clientID" | jq '. | .urls.raw' | sed 's/"//g')
wget $url -O $HOME/Pictures/wallpapers/current.png & > /dev/null
rm -f $path/saved.txt
fi

sleep 4

if [[ $1 == "kde" ]]; then
dbus-send --session --dest=org.kde.plasmashell --type=method_call /PlasmaShell org.kde.PlasmaShell.evaluateScript 'string:
dbus-send --session --dest=org.kde.plasmashell --type=method_call /PlasmaShell org.kde.PlasmaShell.evaluateScript 'string:
var Desktops = desktops();
for (i=0;i<Desktops.length;i++) {
d = Desktops[i];
d.wallpaperPlugin = "org.kde.image";
d.currentConfigGroup = Array("Wallpaper",
"org.kde.image",
"General");
d.writeConfig("Image", "file://'$HOME'/Pictures/wallpapers/background.jpg");
d.writeConfig("Image", "file:///usr/share/wallpapers/Canopee/contents/images/3840x2160.png");
}'

dbus-send --session --dest=org.kde.plasmashell --type=method_call /PlasmaShell org.kde.PlasmaShell.evaluateScript 'string:
Expand All @@ -70,6 +77,6 @@ elif [[ $1 == "nitrogen" ]]; then
sleep 2 && nitrogen --restore
fi
echo $chosenCat > $path/chosenCat.txt
sleep 5
sleep 2
notify-send "Wallpaper changed, new category: $chosenCat"
echo "Wallpaper changed, new category: $chosenCat"

0 comments on commit 9bab913

Please sign in to comment.