Last active
August 29, 2015 13:56
-
-
Save kalkun/8943594 to your computer and use it in GitHub Desktop.
Install script for getwallpaper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# user variable should be passed when invoking script | |
# this way the crontab can be installed for the appropiate user | |
# while having permission to move getwallpaper to executable path | |
user=$1 | |
# make directories | |
#mkdir ~/tmp | |
if [ ! -d ~/Pictures/RWallpapers ]; then | |
mkdir ~/Pictures/RWallpapers | |
fi | |
# get script and save to new tmp folder as getwallpaper | |
curl -o ~/getwallpaper https://gist.githubusercontent.com/kalkun/8386313/raw | |
# make new file getwallpapers executable | |
chmod +x ~/getwallpaper | |
# move to your path on MAC unix | |
if [ -d /usr/local/bin ]; then | |
echo "moving script to /usr/local/bin" | |
mv ~/getwallpaper /usr/local/bin/ | |
elif [ -d /usr/bin ]; then | |
echo "moving script to /usr/bin" | |
mv ~/getwallpaper /usr/bin/ | |
else | |
echo "Could not find a /usr/local/bin or /usr/bin folder." | |
echo "Where do you want to put the script 'getwallpaper' ?" | |
echo -e "\nYou can use ~ to indicate home folder as in:" | |
echo "~/Desktop/" | |
echo "to indicate your desktop." | |
read folder | |
mv ~/getwallpaper $folder | |
fi | |
# remove old script if exists: | |
if [ -f ~/tmp/getwallpapers ]; then | |
echo "Deleting old getwallpapers script" | |
rm ~/tmp/getwallpapers | |
echo "deleting old getwallpapers script from crontab" | |
# remove old getwallpapers call from crontab: | |
crontab -u $user -l | sed '/^.*getwallpaper.*$/d' >> tempfile | |
crontab -u $user tempfile | |
rm tempfile | |
fi | |
# install new crontab to execute the script every half an hour | |
echo "*/30 * * * * getwallpaper" >> tempfile | |
echo "installing crontab for $user" | |
crontab -u $user tempfile | |
# crontab is installed - remove tempfile | |
echo "cleaning up" | |
rm tempfile | |
rm tmp_install |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Install wallpaper
To install just copy+paste the following code into your terminal:
That's it now the getwallpaper script is saved and scheduled to run every half an hour.
Syntax
Any subreddit can be targeted to fetch a wallpaper sorted in anyway that reddit provides with the following syntax:
Both arguments are optional, if no arguments are passed then a wallpaper is fetched from r/wallpapers sorted by hot. If one argument is provided then that subreddit is targeted sorted by hot.
Example
The following will fetch a wallpaper from r/art sorted by new:
This example sets the wallpaper after what is hot on r/earthporn:
Settings
Scheduling
The script is by default set to run every half an hour, fetching a wallpaper from r/wallpapers.
This can be changed by editing the crontab in the following way.
To open your crontable with the scheduled cronjobs in editor mode:
Then change the line that includes the getwallpaper script. Either to include the arguments you prefer, or to prevent the automatic setting of a new wallpaper, you may simply delete the line or insert an '#' in front of the line to uncomment it.
Log file
By default a log file is enabled this can be changed by setting the 'log' variable on line 29 to 'false'. The log file is saved to ~/tmp/log by default, this location can be changed by changing the 'logfile' variable.
To view the logfile type:
That's it :)