Change dynamic wallpaper directory every season
I want to have my wallpaper be seasonal (summer, fall, winter, spring), but also update daily with a seasonal themed wallpaper.
So essentially, I am thinking of having 4 directories (summer, fall, winter, spring
). During summer, my wallpaper background would rotate through the images in the summer
directory on a daily basis. Then on Sept. 21, the wallpaper directory would change to fall
, and the wallpaper would then cycle through those images on a daily basis, etc.
I am comfortable writing a script, but where would I start?
How this question is unique
Edit: To clarify further about what makes this question unique. While there are many methods to create a slideshow, they all depend on setting the images directory. What I am asking is how to dynamically change the images directory. So slide show today comes out of the /images/winter/
directory, and slide show in spring comes out of the /images/spring/
directory. I could manually do this by just changing the directory in the appearance settings every season, but I don't want to have to that when I can tell the computer to do it for me.
scripts wallpaper
New contributor
add a comment |
I want to have my wallpaper be seasonal (summer, fall, winter, spring), but also update daily with a seasonal themed wallpaper.
So essentially, I am thinking of having 4 directories (summer, fall, winter, spring
). During summer, my wallpaper background would rotate through the images in the summer
directory on a daily basis. Then on Sept. 21, the wallpaper directory would change to fall
, and the wallpaper would then cycle through those images on a daily basis, etc.
I am comfortable writing a script, but where would I start?
How this question is unique
Edit: To clarify further about what makes this question unique. While there are many methods to create a slideshow, they all depend on setting the images directory. What I am asking is how to dynamically change the images directory. So slide show today comes out of the /images/winter/
directory, and slide show in spring comes out of the /images/spring/
directory. I could manually do this by just changing the directory in the appearance settings every season, but I don't want to have to that when I can tell the computer to do it for me.
scripts wallpaper
New contributor
do you have your wall papers and folders ready? how many wallpapers in each of 4 seasonal folders.
– PRATAP
Dec 14 at 17:23
what is your Ubuntu version that you are going to do this on?
– PRATAP
Dec 14 at 17:24
Voting to Leave Open This question is more about scripting based on today's date and seasons of the year.
– WinEunuuchs2Unix
Dec 15 at 18:09
add a comment |
I want to have my wallpaper be seasonal (summer, fall, winter, spring), but also update daily with a seasonal themed wallpaper.
So essentially, I am thinking of having 4 directories (summer, fall, winter, spring
). During summer, my wallpaper background would rotate through the images in the summer
directory on a daily basis. Then on Sept. 21, the wallpaper directory would change to fall
, and the wallpaper would then cycle through those images on a daily basis, etc.
I am comfortable writing a script, but where would I start?
How this question is unique
Edit: To clarify further about what makes this question unique. While there are many methods to create a slideshow, they all depend on setting the images directory. What I am asking is how to dynamically change the images directory. So slide show today comes out of the /images/winter/
directory, and slide show in spring comes out of the /images/spring/
directory. I could manually do this by just changing the directory in the appearance settings every season, but I don't want to have to that when I can tell the computer to do it for me.
scripts wallpaper
New contributor
I want to have my wallpaper be seasonal (summer, fall, winter, spring), but also update daily with a seasonal themed wallpaper.
So essentially, I am thinking of having 4 directories (summer, fall, winter, spring
). During summer, my wallpaper background would rotate through the images in the summer
directory on a daily basis. Then on Sept. 21, the wallpaper directory would change to fall
, and the wallpaper would then cycle through those images on a daily basis, etc.
I am comfortable writing a script, but where would I start?
How this question is unique
Edit: To clarify further about what makes this question unique. While there are many methods to create a slideshow, they all depend on setting the images directory. What I am asking is how to dynamically change the images directory. So slide show today comes out of the /images/winter/
directory, and slide show in spring comes out of the /images/spring/
directory. I could manually do this by just changing the directory in the appearance settings every season, but I don't want to have to that when I can tell the computer to do it for me.
scripts wallpaper
scripts wallpaper
New contributor
New contributor
edited Dec 15 at 18:06
WinEunuuchs2Unix
41.7k1070158
41.7k1070158
New contributor
asked Dec 14 at 17:19
Joseph Gilgen
314
314
New contributor
New contributor
do you have your wall papers and folders ready? how many wallpapers in each of 4 seasonal folders.
– PRATAP
Dec 14 at 17:23
what is your Ubuntu version that you are going to do this on?
– PRATAP
Dec 14 at 17:24
Voting to Leave Open This question is more about scripting based on today's date and seasons of the year.
– WinEunuuchs2Unix
Dec 15 at 18:09
add a comment |
do you have your wall papers and folders ready? how many wallpapers in each of 4 seasonal folders.
– PRATAP
Dec 14 at 17:23
what is your Ubuntu version that you are going to do this on?
– PRATAP
Dec 14 at 17:24
Voting to Leave Open This question is more about scripting based on today's date and seasons of the year.
– WinEunuuchs2Unix
Dec 15 at 18:09
do you have your wall papers and folders ready? how many wallpapers in each of 4 seasonal folders.
– PRATAP
Dec 14 at 17:23
do you have your wall papers and folders ready? how many wallpapers in each of 4 seasonal folders.
– PRATAP
Dec 14 at 17:23
what is your Ubuntu version that you are going to do this on?
– PRATAP
Dec 14 at 17:24
what is your Ubuntu version that you are going to do this on?
– PRATAP
Dec 14 at 17:24
Voting to Leave Open This question is more about scripting based on today's date and seasons of the year.
– WinEunuuchs2Unix
Dec 15 at 18:09
Voting to Leave Open This question is more about scripting based on today's date and seasons of the year.
– WinEunuuchs2Unix
Dec 15 at 18:09
add a comment |
3 Answers
3
active
oldest
votes
The basic question is how to do something at the start of Spring, Summer, Fall and Winter. For this I would create a bash script that runs on boot, rather than clogging up cron
with entries.
I've approached this answer using the OP's question "How do I develop a script?". So I've deviated from usual method of simply posting a bash script and enhanced the answer with:
- References are included within the code. They link to Stack Exchange answers for solving specific problems. For example: How to copy files, How to get day of year, etc.
- A section on "Testing" is provided as it is something we all need to do
- A section on "Enhancements" is provided because software is usually developed in versions where each is incrementally better than the previous version.
When do seasons start?
From the Farmer's Almanac:
Seasons of 2018
Season Astronomical Start Meteorological Start
====== ===================================== =====================
SPRING Tuesday, March 20, 12:15 P.M. EDT Thursday, March 1
SUMMER Thursday, June 21, 6:07 A.M. EDT Friday, June 1
FALL Saturday, September 22, 9:54 P.M. EDT Saturday, September 1
WINTER Friday, December 21, 5:23 P.M. EST Saturday, December 1
Convert season start date to Day of Year
For our bash
script to work we need to know what day of the year each seasons start.
$ echo $(date --date="March 20" '+%j')
079
$ echo $(date --date="June 21" '+%j')
172
$ echo $(date --date="Sep 22" '+%j')
265
$ echo $(date --date="Dec 21" '+%j')
355
# Reference: https://unix.stackexchange.com/questions/352176/take-input-arguments-and-pass-them-to-date
Create bash script: season.sh
Open the terminal using: Ctrl+Alt+T
Create the directory if it doesn't exist: mkdir -p ~/bin
Edit the script using: gedit ~/bin/season.sh
Note: Lubuntu user's need to useleafpad
instead ofgedit
Copy and paste the following lines into gedit
:
#!/bin/bash
# NAME: season.sh
# PATH: ~/bin
# DATE: December 15, 2018
# NOTE: Written for: https://askubuntu.com/questions/1100934/change-dynamic-wallpaper-directory-every-season/1102084#1102084
# User defined variables, change to suit your needs
# Our directory names, lines indented for cosmetic reasons only
SlideShowDir="~/Season Slide Show"
SpringDir="~/Pictures/Spring Slide Show"
SummerDir="~/Pictures/Summer Slide Show"
FallDir="~/Pictures/Fall Slide Show"
WinterDir="~/Pictures/Winter Slide Show"
CheckTripWire () {
# Our last season is in "~/Season Slide Show/CurrentSeason"
LastSeasonFilename="$SlideShowDir"/CurrentSeason
LastSeason=$(cat "$LastSeasonFilename")
[[ "$LastSeason" == "$Season" ]] && return 0 # Season still the same
# We now know our season has changed.
rm -f "$SlideShowDir"/{*,.*} # Erase all files in target
# Reference: https://askubuntu.com/questions/60228/how-to-remove-all-files-from-a-directory
echo "$Season" > "$LastSeasonFilename" # Record new season in target
# Copy new slide show based on season
if (( "$Season" == SPRING)) ; then
cp -R "$SpringDir"/. "$SlideShowDir"/
# Reference: https://stackoverflow.com/questions/3643848/copy-files-from-one-directory-into-an-existing-directory
elif (( "$Season" == SUMMER)) ; then
cp -R "$SummerDir"/. "$SlideShowDir"/
elif (( "$Season" == FALL)) ; then
cp -R "$FallDir"/. "$SlideShowDir"/
else
cp -R "$WinterDir"/. "$SlideShowDir"/
fi
} # End of CheckTripWire () function.
# Start of Mainline
DOY=$(date '+%j') # DOY = Current Day of Year
# Reference: https://stackoverflow.com/questions/10112453/how-to-get-day-of-the-year-in-shell
if ((DOY>=079 && DOY<172)) ; then
Season="SPRING" # Spring has sprung!
# Reference: https://stackoverflow.com/questions/12614011/using-case-for-a-range-of-numbers-in-bash
elif ((DOY>=172 && DOY<265)) ; then
Season="SUMMER" # Hit the beach!
elif ((DOY>=265 && DOY<355)) ; then
Season="FALL" # Rake those leaves!
else
Season="WINTER" # Shovel the snow!
fi
# Current season establish, now see if we tripped the wire
CheckTripWire
exit 0 # Command not necessary but good habit to signify no Abend.
Save the file in gedit
. Now mark it as executable using:
chmod a+x ~/bin/season.sh
Next we need to add it to startup applications. Reference: How do I start applications automatically on login?
Note: You probably already have your slide show setup in startup applications. You will want to use season.sh
BEFORE your regular slide show as it deletes and copies files which would crash the slide show program if it started first.
Testing
You will want to test season.sh
script when you create it and not wait a year to see if it works properly or not. Reference: https://serverfault.com/questions/138325/faking-the-date-for-a-specific-shell-session
Enhancements
After initially developing a script it is common to enhance it Days, Weeks, Months or even Years later. This section discusses some enhancements you might want to make to session.sh
down the road.
Compress files to save disk space
Consider keeping the off-season images compressed in TAR (Tape Archive) format to save on disk space. Then replace the cp
(Copy) command with the tar
command to un-compress the files. Reference: https://www.rootusers.com/23-tar-command-examples-for-linux/:
For example, we would change:
cp -R "$SpringDir"/. "$SlideShowDir"/
To:
tar -xf "$SpringDir"archive.tar -C "$SlideShowDir"/
... and so on for the other seasons.
Setup variables for season start
Using variables for season start days makes it easier to modify the script and makes the code easier to read (aka code readability).
Consider setting up Variables for start of season:
SpringStart=079
SummerStart=179
FallStart=265
WinterStart=355
Define the variables at the top of the script to make them easier to spot and change. You might want to do this for leap years. You might want to change to "Meteorological" season starts instead of "Astronomical" start dates.
Then change these lines:
if ((DOY>=079 && DOY<172)) ; then
elif ((DOY>=172 && DOY<265)) ; then
elif ((DOY>=265 && DOY<355)) ; then
To this:
if ((DOY>="$SpringStart" && DOY<"$SummerStart")) ; then
elif ((DOY>="$SummerStart" && DOY<"$FallStart")) ; then
elif ((DOY>="$FallStart" && DOY<"$WinterStart")) ; then
NOTE: I was hoping to finish this answer in an hour but it's been two hours and I have to do some Saturday Shopping. To Be Continued...
very nice point @WinEunnuchs2Unix. you got the Question very clearly. i am eager to know how this script is useful in relation to Question. i am intrested to know, after getting DayOfYear by your script..how the system will change the wall paper. Thank You.
– PRATAP
Dec 15 at 14:47
@PRATAP I regret I didn't get the whole answer completely polished in two hours but enough is there to answer your comment I believe.
– WinEunuuchs2Unix
Dec 15 at 15:32
excellent coding... now i understood. Thank You.
– PRATAP
Dec 15 at 15:40
Thanks for the answer. I accepted this because 1) I needed to practice with bash and it was a great tutorial, and 2) It was really complete and well laid out. Utlimately, I combined it with @unutbu answer to just change a symbolic link instead of copying and pasting files. Here is a gist with the code. If you just want a simple method to do this without creating a script, I think @unutbu answer is probably the way to go.
– Joseph Gilgen
Dec 17 at 22:21
@JosephGilgen I agree the cron method is simplest and up-voted it. I approached the question as requiring a scripting answer with the objective of teaching a little scripting along the way. I included references to other Stack Exchange answers to show where the theory / implementation of different coding techniques come from. It was a thoroughly enjoyable project and I thank you for posting the question. Which I also hopes garners many upvotes :)
– WinEunuuchs2Unix
Dec 17 at 23:18
add a comment |
Perhaps this is an easier way:
Create a symlink from
~/images/mybackgrounds
to~/images/spring
:
ln -s ~/images/spring ~/images/mybackgrounds
Use one of these methods to display a background slideshow using images from
~/images/mybackgrounds
.
Set up crontab entries to change the symlink on particular days. Create a file called
~/mycrontab
with these contents:
# min hr day mon dow
0 9 21 3 * ln -sf ~/images/spring ~/images/mybackgrounds
0 9 21 6 * ln -sf ~/images/summer ~/images/mybackgrounds
0 9 21 9 * ln -sf ~/images/fall ~/images/mybackgrounds
0 9 21 12 * ln -sf ~/images/winter ~/images/mybackgrounds
Run
crontab ~/mycrontab
to register the crontab entries. On March 21 at 9AM,
crond
will run the command
ln -sf ~/images/spring ~/images/mybackgrounds
thus linking ~/images/mybackgrounds
to ~/images/spring
. On Jun 21 at 9AM,
crond
will change the symlink so that ~/images/mybackgrounds
points to
~/images/summer
. The slideshow program is configured to select a file from
~/images/mybackgrounds
. The path to ~/images/mybackgrounds
stays the same,
but now all the contents are different because the symlink points to a different
location. The crontab entries for Sep 21 and Dec 21 pull the same trick.
This is really the most simple and straight forward method to accomplish what I was trying to do. No scripting, just updating the slideshow directory with a cron job. While I accepted the answer from @WinEunuuchs2Unix, perhaps upvotes will really show this to be the most useful answer.
– Joseph Gilgen
Dec 17 at 22:24
Upvote from me :)
– WinEunuuchs2Unix
Dec 17 at 23:15
add a comment |
Step 1: Create a slideshow.py script
Save this in a file called ~/bin/slideshow.py
:
#!/usr/bin/env python
import os
import datetime as DT
import itertools as IT
import bisect
import random
import subprocess
# customize cutoffs and image_dirs however you like, but note that there must be
# the same number of items in each, and the items in cutoffs must be in sorted order.
cutoffs = [(3, 21), (6, 21), (9, 21), (12, 21)]
image_dirs = ['~/images/winter', '~/images/spring', '~/images/summer', '~/images/fall']
image_dirs = list(map(os.path.expanduser, image_dirs))
today = DT.date.today()
year = today.year
# convert the cutoffs to actual dates
cutoff_dates = [DT.date(year, m, d) for m, d in cutoffs]
# find the index into cutoff_dates where today would fit and still keep the list sorted
idx = bisect.bisect(cutoff_dates, today)
# use idx to get the corresponding image directory
image_dir = next(IT.islice(IT.cycle(image_dirs), idx, idx+1))
# list all the files in image_dir (even in subdirectories, and following symlinks)
files = [os.path.join(root, filename)
for root, dirs, files in os.walk(image_dirs[idx], followlinks=True)
for filename in files]
# pick a file at random
imagefile = os.path.abspath(random.choice(files))
# find the current process's effective user id (EUID)
euid = str(os.geteuid())
# find the pid of the current EUID's gnome-session
pid = subprocess.check_output(['pgrep', '--euid', euid, 'gnome-session']).strip().decode()
# load all the environment variables of gnome-session
env = open('/proc/{}/environ'.format(pid), 'rb').read().strip(b'x00')
env = dict([item.split(b'=', 1) for item in env.split(b'x00')])
# get the value of DBUS_SESSION_BUS_ADDRESS environment variable
key = b'DBUS_SESSION_BUS_ADDRESS'
env = {key: env[key]}
# call gsettings to change the background to display the selected file
# with the DBUS_SESSION_BUS_ADDRESS environment variable set appropriately
subprocess.call(['gsettings', 'set', 'org.gnome.desktop.background', 'picture-uri',
'file://{}'.format(imagefile)], env=env)
Step 2: Make it executable:
chmod 755 ~/bin/slideshow.py
To test that things are working as expected, you can open a terminal and run
slideshow.py
repeatedly. You should see the background changing. Note that
slideshow.py
looks for images in one of 4 directories, ~/images/spring
,
~/images/summer
, ~/images/fall
, or ~/images/winter
depending on the season.
Step 3: Configure crontab
You can use cron to periodically
run a command to change the background, say, once every day or once every minute
minutes.
Make a file called, say, ~/mycrontab
, and
put something like this inside:
# min hr day mon dow
# 0 9 * * * ~/bin/slideshow.py # run once at 9AM
* * * * * ~/bin/slideshow.py # run once every minute
Then run
crontab ~/mycrontab
to register the change to your crontab.
You should now see the background changing once every minute. (You might even enjoy keeping it this way.)
crontab
will ignore lines which begin with #
. So if you want the background
to change once per day, uncomment the second line and comment-out the third so
that ~/mycrontab
now looks like this:
# min hr day mon dow
0 9 * * * ~/bin/slideshow.py # run once at 9AM
# * * * * * ~/bin/slideshow.py # run once every minute
Note however that cron will only run this command if you are logged into the machine
at 9AM that day.
I like the direction this is going. I have not had a chance to play with it yet. What I am trying to do though is change the directory every season, so it would be something like/path/to/spring/*.png
in spring, but I don't quite think that would work.
– Joseph Gilgen
Dec 14 at 22:29
Hope you don't mind but I edited your answer to use Python Language highlighting. I also changedchown
tochmod
which I think was your original intent.
– WinEunuuchs2Unix
Dec 15 at 18:18
@WinEunuuchs2Unix: Thanks for the corrections.
– unutbu
Dec 15 at 18:20
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "89"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Joseph Gilgen is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1100934%2fchange-dynamic-wallpaper-directory-every-season%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
The basic question is how to do something at the start of Spring, Summer, Fall and Winter. For this I would create a bash script that runs on boot, rather than clogging up cron
with entries.
I've approached this answer using the OP's question "How do I develop a script?". So I've deviated from usual method of simply posting a bash script and enhanced the answer with:
- References are included within the code. They link to Stack Exchange answers for solving specific problems. For example: How to copy files, How to get day of year, etc.
- A section on "Testing" is provided as it is something we all need to do
- A section on "Enhancements" is provided because software is usually developed in versions where each is incrementally better than the previous version.
When do seasons start?
From the Farmer's Almanac:
Seasons of 2018
Season Astronomical Start Meteorological Start
====== ===================================== =====================
SPRING Tuesday, March 20, 12:15 P.M. EDT Thursday, March 1
SUMMER Thursday, June 21, 6:07 A.M. EDT Friday, June 1
FALL Saturday, September 22, 9:54 P.M. EDT Saturday, September 1
WINTER Friday, December 21, 5:23 P.M. EST Saturday, December 1
Convert season start date to Day of Year
For our bash
script to work we need to know what day of the year each seasons start.
$ echo $(date --date="March 20" '+%j')
079
$ echo $(date --date="June 21" '+%j')
172
$ echo $(date --date="Sep 22" '+%j')
265
$ echo $(date --date="Dec 21" '+%j')
355
# Reference: https://unix.stackexchange.com/questions/352176/take-input-arguments-and-pass-them-to-date
Create bash script: season.sh
Open the terminal using: Ctrl+Alt+T
Create the directory if it doesn't exist: mkdir -p ~/bin
Edit the script using: gedit ~/bin/season.sh
Note: Lubuntu user's need to useleafpad
instead ofgedit
Copy and paste the following lines into gedit
:
#!/bin/bash
# NAME: season.sh
# PATH: ~/bin
# DATE: December 15, 2018
# NOTE: Written for: https://askubuntu.com/questions/1100934/change-dynamic-wallpaper-directory-every-season/1102084#1102084
# User defined variables, change to suit your needs
# Our directory names, lines indented for cosmetic reasons only
SlideShowDir="~/Season Slide Show"
SpringDir="~/Pictures/Spring Slide Show"
SummerDir="~/Pictures/Summer Slide Show"
FallDir="~/Pictures/Fall Slide Show"
WinterDir="~/Pictures/Winter Slide Show"
CheckTripWire () {
# Our last season is in "~/Season Slide Show/CurrentSeason"
LastSeasonFilename="$SlideShowDir"/CurrentSeason
LastSeason=$(cat "$LastSeasonFilename")
[[ "$LastSeason" == "$Season" ]] && return 0 # Season still the same
# We now know our season has changed.
rm -f "$SlideShowDir"/{*,.*} # Erase all files in target
# Reference: https://askubuntu.com/questions/60228/how-to-remove-all-files-from-a-directory
echo "$Season" > "$LastSeasonFilename" # Record new season in target
# Copy new slide show based on season
if (( "$Season" == SPRING)) ; then
cp -R "$SpringDir"/. "$SlideShowDir"/
# Reference: https://stackoverflow.com/questions/3643848/copy-files-from-one-directory-into-an-existing-directory
elif (( "$Season" == SUMMER)) ; then
cp -R "$SummerDir"/. "$SlideShowDir"/
elif (( "$Season" == FALL)) ; then
cp -R "$FallDir"/. "$SlideShowDir"/
else
cp -R "$WinterDir"/. "$SlideShowDir"/
fi
} # End of CheckTripWire () function.
# Start of Mainline
DOY=$(date '+%j') # DOY = Current Day of Year
# Reference: https://stackoverflow.com/questions/10112453/how-to-get-day-of-the-year-in-shell
if ((DOY>=079 && DOY<172)) ; then
Season="SPRING" # Spring has sprung!
# Reference: https://stackoverflow.com/questions/12614011/using-case-for-a-range-of-numbers-in-bash
elif ((DOY>=172 && DOY<265)) ; then
Season="SUMMER" # Hit the beach!
elif ((DOY>=265 && DOY<355)) ; then
Season="FALL" # Rake those leaves!
else
Season="WINTER" # Shovel the snow!
fi
# Current season establish, now see if we tripped the wire
CheckTripWire
exit 0 # Command not necessary but good habit to signify no Abend.
Save the file in gedit
. Now mark it as executable using:
chmod a+x ~/bin/season.sh
Next we need to add it to startup applications. Reference: How do I start applications automatically on login?
Note: You probably already have your slide show setup in startup applications. You will want to use season.sh
BEFORE your regular slide show as it deletes and copies files which would crash the slide show program if it started first.
Testing
You will want to test season.sh
script when you create it and not wait a year to see if it works properly or not. Reference: https://serverfault.com/questions/138325/faking-the-date-for-a-specific-shell-session
Enhancements
After initially developing a script it is common to enhance it Days, Weeks, Months or even Years later. This section discusses some enhancements you might want to make to session.sh
down the road.
Compress files to save disk space
Consider keeping the off-season images compressed in TAR (Tape Archive) format to save on disk space. Then replace the cp
(Copy) command with the tar
command to un-compress the files. Reference: https://www.rootusers.com/23-tar-command-examples-for-linux/:
For example, we would change:
cp -R "$SpringDir"/. "$SlideShowDir"/
To:
tar -xf "$SpringDir"archive.tar -C "$SlideShowDir"/
... and so on for the other seasons.
Setup variables for season start
Using variables for season start days makes it easier to modify the script and makes the code easier to read (aka code readability).
Consider setting up Variables for start of season:
SpringStart=079
SummerStart=179
FallStart=265
WinterStart=355
Define the variables at the top of the script to make them easier to spot and change. You might want to do this for leap years. You might want to change to "Meteorological" season starts instead of "Astronomical" start dates.
Then change these lines:
if ((DOY>=079 && DOY<172)) ; then
elif ((DOY>=172 && DOY<265)) ; then
elif ((DOY>=265 && DOY<355)) ; then
To this:
if ((DOY>="$SpringStart" && DOY<"$SummerStart")) ; then
elif ((DOY>="$SummerStart" && DOY<"$FallStart")) ; then
elif ((DOY>="$FallStart" && DOY<"$WinterStart")) ; then
NOTE: I was hoping to finish this answer in an hour but it's been two hours and I have to do some Saturday Shopping. To Be Continued...
very nice point @WinEunnuchs2Unix. you got the Question very clearly. i am eager to know how this script is useful in relation to Question. i am intrested to know, after getting DayOfYear by your script..how the system will change the wall paper. Thank You.
– PRATAP
Dec 15 at 14:47
@PRATAP I regret I didn't get the whole answer completely polished in two hours but enough is there to answer your comment I believe.
– WinEunuuchs2Unix
Dec 15 at 15:32
excellent coding... now i understood. Thank You.
– PRATAP
Dec 15 at 15:40
Thanks for the answer. I accepted this because 1) I needed to practice with bash and it was a great tutorial, and 2) It was really complete and well laid out. Utlimately, I combined it with @unutbu answer to just change a symbolic link instead of copying and pasting files. Here is a gist with the code. If you just want a simple method to do this without creating a script, I think @unutbu answer is probably the way to go.
– Joseph Gilgen
Dec 17 at 22:21
@JosephGilgen I agree the cron method is simplest and up-voted it. I approached the question as requiring a scripting answer with the objective of teaching a little scripting along the way. I included references to other Stack Exchange answers to show where the theory / implementation of different coding techniques come from. It was a thoroughly enjoyable project and I thank you for posting the question. Which I also hopes garners many upvotes :)
– WinEunuuchs2Unix
Dec 17 at 23:18
add a comment |
The basic question is how to do something at the start of Spring, Summer, Fall and Winter. For this I would create a bash script that runs on boot, rather than clogging up cron
with entries.
I've approached this answer using the OP's question "How do I develop a script?". So I've deviated from usual method of simply posting a bash script and enhanced the answer with:
- References are included within the code. They link to Stack Exchange answers for solving specific problems. For example: How to copy files, How to get day of year, etc.
- A section on "Testing" is provided as it is something we all need to do
- A section on "Enhancements" is provided because software is usually developed in versions where each is incrementally better than the previous version.
When do seasons start?
From the Farmer's Almanac:
Seasons of 2018
Season Astronomical Start Meteorological Start
====== ===================================== =====================
SPRING Tuesday, March 20, 12:15 P.M. EDT Thursday, March 1
SUMMER Thursday, June 21, 6:07 A.M. EDT Friday, June 1
FALL Saturday, September 22, 9:54 P.M. EDT Saturday, September 1
WINTER Friday, December 21, 5:23 P.M. EST Saturday, December 1
Convert season start date to Day of Year
For our bash
script to work we need to know what day of the year each seasons start.
$ echo $(date --date="March 20" '+%j')
079
$ echo $(date --date="June 21" '+%j')
172
$ echo $(date --date="Sep 22" '+%j')
265
$ echo $(date --date="Dec 21" '+%j')
355
# Reference: https://unix.stackexchange.com/questions/352176/take-input-arguments-and-pass-them-to-date
Create bash script: season.sh
Open the terminal using: Ctrl+Alt+T
Create the directory if it doesn't exist: mkdir -p ~/bin
Edit the script using: gedit ~/bin/season.sh
Note: Lubuntu user's need to useleafpad
instead ofgedit
Copy and paste the following lines into gedit
:
#!/bin/bash
# NAME: season.sh
# PATH: ~/bin
# DATE: December 15, 2018
# NOTE: Written for: https://askubuntu.com/questions/1100934/change-dynamic-wallpaper-directory-every-season/1102084#1102084
# User defined variables, change to suit your needs
# Our directory names, lines indented for cosmetic reasons only
SlideShowDir="~/Season Slide Show"
SpringDir="~/Pictures/Spring Slide Show"
SummerDir="~/Pictures/Summer Slide Show"
FallDir="~/Pictures/Fall Slide Show"
WinterDir="~/Pictures/Winter Slide Show"
CheckTripWire () {
# Our last season is in "~/Season Slide Show/CurrentSeason"
LastSeasonFilename="$SlideShowDir"/CurrentSeason
LastSeason=$(cat "$LastSeasonFilename")
[[ "$LastSeason" == "$Season" ]] && return 0 # Season still the same
# We now know our season has changed.
rm -f "$SlideShowDir"/{*,.*} # Erase all files in target
# Reference: https://askubuntu.com/questions/60228/how-to-remove-all-files-from-a-directory
echo "$Season" > "$LastSeasonFilename" # Record new season in target
# Copy new slide show based on season
if (( "$Season" == SPRING)) ; then
cp -R "$SpringDir"/. "$SlideShowDir"/
# Reference: https://stackoverflow.com/questions/3643848/copy-files-from-one-directory-into-an-existing-directory
elif (( "$Season" == SUMMER)) ; then
cp -R "$SummerDir"/. "$SlideShowDir"/
elif (( "$Season" == FALL)) ; then
cp -R "$FallDir"/. "$SlideShowDir"/
else
cp -R "$WinterDir"/. "$SlideShowDir"/
fi
} # End of CheckTripWire () function.
# Start of Mainline
DOY=$(date '+%j') # DOY = Current Day of Year
# Reference: https://stackoverflow.com/questions/10112453/how-to-get-day-of-the-year-in-shell
if ((DOY>=079 && DOY<172)) ; then
Season="SPRING" # Spring has sprung!
# Reference: https://stackoverflow.com/questions/12614011/using-case-for-a-range-of-numbers-in-bash
elif ((DOY>=172 && DOY<265)) ; then
Season="SUMMER" # Hit the beach!
elif ((DOY>=265 && DOY<355)) ; then
Season="FALL" # Rake those leaves!
else
Season="WINTER" # Shovel the snow!
fi
# Current season establish, now see if we tripped the wire
CheckTripWire
exit 0 # Command not necessary but good habit to signify no Abend.
Save the file in gedit
. Now mark it as executable using:
chmod a+x ~/bin/season.sh
Next we need to add it to startup applications. Reference: How do I start applications automatically on login?
Note: You probably already have your slide show setup in startup applications. You will want to use season.sh
BEFORE your regular slide show as it deletes and copies files which would crash the slide show program if it started first.
Testing
You will want to test season.sh
script when you create it and not wait a year to see if it works properly or not. Reference: https://serverfault.com/questions/138325/faking-the-date-for-a-specific-shell-session
Enhancements
After initially developing a script it is common to enhance it Days, Weeks, Months or even Years later. This section discusses some enhancements you might want to make to session.sh
down the road.
Compress files to save disk space
Consider keeping the off-season images compressed in TAR (Tape Archive) format to save on disk space. Then replace the cp
(Copy) command with the tar
command to un-compress the files. Reference: https://www.rootusers.com/23-tar-command-examples-for-linux/:
For example, we would change:
cp -R "$SpringDir"/. "$SlideShowDir"/
To:
tar -xf "$SpringDir"archive.tar -C "$SlideShowDir"/
... and so on for the other seasons.
Setup variables for season start
Using variables for season start days makes it easier to modify the script and makes the code easier to read (aka code readability).
Consider setting up Variables for start of season:
SpringStart=079
SummerStart=179
FallStart=265
WinterStart=355
Define the variables at the top of the script to make them easier to spot and change. You might want to do this for leap years. You might want to change to "Meteorological" season starts instead of "Astronomical" start dates.
Then change these lines:
if ((DOY>=079 && DOY<172)) ; then
elif ((DOY>=172 && DOY<265)) ; then
elif ((DOY>=265 && DOY<355)) ; then
To this:
if ((DOY>="$SpringStart" && DOY<"$SummerStart")) ; then
elif ((DOY>="$SummerStart" && DOY<"$FallStart")) ; then
elif ((DOY>="$FallStart" && DOY<"$WinterStart")) ; then
NOTE: I was hoping to finish this answer in an hour but it's been two hours and I have to do some Saturday Shopping. To Be Continued...
very nice point @WinEunnuchs2Unix. you got the Question very clearly. i am eager to know how this script is useful in relation to Question. i am intrested to know, after getting DayOfYear by your script..how the system will change the wall paper. Thank You.
– PRATAP
Dec 15 at 14:47
@PRATAP I regret I didn't get the whole answer completely polished in two hours but enough is there to answer your comment I believe.
– WinEunuuchs2Unix
Dec 15 at 15:32
excellent coding... now i understood. Thank You.
– PRATAP
Dec 15 at 15:40
Thanks for the answer. I accepted this because 1) I needed to practice with bash and it was a great tutorial, and 2) It was really complete and well laid out. Utlimately, I combined it with @unutbu answer to just change a symbolic link instead of copying and pasting files. Here is a gist with the code. If you just want a simple method to do this without creating a script, I think @unutbu answer is probably the way to go.
– Joseph Gilgen
Dec 17 at 22:21
@JosephGilgen I agree the cron method is simplest and up-voted it. I approached the question as requiring a scripting answer with the objective of teaching a little scripting along the way. I included references to other Stack Exchange answers to show where the theory / implementation of different coding techniques come from. It was a thoroughly enjoyable project and I thank you for posting the question. Which I also hopes garners many upvotes :)
– WinEunuuchs2Unix
Dec 17 at 23:18
add a comment |
The basic question is how to do something at the start of Spring, Summer, Fall and Winter. For this I would create a bash script that runs on boot, rather than clogging up cron
with entries.
I've approached this answer using the OP's question "How do I develop a script?". So I've deviated from usual method of simply posting a bash script and enhanced the answer with:
- References are included within the code. They link to Stack Exchange answers for solving specific problems. For example: How to copy files, How to get day of year, etc.
- A section on "Testing" is provided as it is something we all need to do
- A section on "Enhancements" is provided because software is usually developed in versions where each is incrementally better than the previous version.
When do seasons start?
From the Farmer's Almanac:
Seasons of 2018
Season Astronomical Start Meteorological Start
====== ===================================== =====================
SPRING Tuesday, March 20, 12:15 P.M. EDT Thursday, March 1
SUMMER Thursday, June 21, 6:07 A.M. EDT Friday, June 1
FALL Saturday, September 22, 9:54 P.M. EDT Saturday, September 1
WINTER Friday, December 21, 5:23 P.M. EST Saturday, December 1
Convert season start date to Day of Year
For our bash
script to work we need to know what day of the year each seasons start.
$ echo $(date --date="March 20" '+%j')
079
$ echo $(date --date="June 21" '+%j')
172
$ echo $(date --date="Sep 22" '+%j')
265
$ echo $(date --date="Dec 21" '+%j')
355
# Reference: https://unix.stackexchange.com/questions/352176/take-input-arguments-and-pass-them-to-date
Create bash script: season.sh
Open the terminal using: Ctrl+Alt+T
Create the directory if it doesn't exist: mkdir -p ~/bin
Edit the script using: gedit ~/bin/season.sh
Note: Lubuntu user's need to useleafpad
instead ofgedit
Copy and paste the following lines into gedit
:
#!/bin/bash
# NAME: season.sh
# PATH: ~/bin
# DATE: December 15, 2018
# NOTE: Written for: https://askubuntu.com/questions/1100934/change-dynamic-wallpaper-directory-every-season/1102084#1102084
# User defined variables, change to suit your needs
# Our directory names, lines indented for cosmetic reasons only
SlideShowDir="~/Season Slide Show"
SpringDir="~/Pictures/Spring Slide Show"
SummerDir="~/Pictures/Summer Slide Show"
FallDir="~/Pictures/Fall Slide Show"
WinterDir="~/Pictures/Winter Slide Show"
CheckTripWire () {
# Our last season is in "~/Season Slide Show/CurrentSeason"
LastSeasonFilename="$SlideShowDir"/CurrentSeason
LastSeason=$(cat "$LastSeasonFilename")
[[ "$LastSeason" == "$Season" ]] && return 0 # Season still the same
# We now know our season has changed.
rm -f "$SlideShowDir"/{*,.*} # Erase all files in target
# Reference: https://askubuntu.com/questions/60228/how-to-remove-all-files-from-a-directory
echo "$Season" > "$LastSeasonFilename" # Record new season in target
# Copy new slide show based on season
if (( "$Season" == SPRING)) ; then
cp -R "$SpringDir"/. "$SlideShowDir"/
# Reference: https://stackoverflow.com/questions/3643848/copy-files-from-one-directory-into-an-existing-directory
elif (( "$Season" == SUMMER)) ; then
cp -R "$SummerDir"/. "$SlideShowDir"/
elif (( "$Season" == FALL)) ; then
cp -R "$FallDir"/. "$SlideShowDir"/
else
cp -R "$WinterDir"/. "$SlideShowDir"/
fi
} # End of CheckTripWire () function.
# Start of Mainline
DOY=$(date '+%j') # DOY = Current Day of Year
# Reference: https://stackoverflow.com/questions/10112453/how-to-get-day-of-the-year-in-shell
if ((DOY>=079 && DOY<172)) ; then
Season="SPRING" # Spring has sprung!
# Reference: https://stackoverflow.com/questions/12614011/using-case-for-a-range-of-numbers-in-bash
elif ((DOY>=172 && DOY<265)) ; then
Season="SUMMER" # Hit the beach!
elif ((DOY>=265 && DOY<355)) ; then
Season="FALL" # Rake those leaves!
else
Season="WINTER" # Shovel the snow!
fi
# Current season establish, now see if we tripped the wire
CheckTripWire
exit 0 # Command not necessary but good habit to signify no Abend.
Save the file in gedit
. Now mark it as executable using:
chmod a+x ~/bin/season.sh
Next we need to add it to startup applications. Reference: How do I start applications automatically on login?
Note: You probably already have your slide show setup in startup applications. You will want to use season.sh
BEFORE your regular slide show as it deletes and copies files which would crash the slide show program if it started first.
Testing
You will want to test season.sh
script when you create it and not wait a year to see if it works properly or not. Reference: https://serverfault.com/questions/138325/faking-the-date-for-a-specific-shell-session
Enhancements
After initially developing a script it is common to enhance it Days, Weeks, Months or even Years later. This section discusses some enhancements you might want to make to session.sh
down the road.
Compress files to save disk space
Consider keeping the off-season images compressed in TAR (Tape Archive) format to save on disk space. Then replace the cp
(Copy) command with the tar
command to un-compress the files. Reference: https://www.rootusers.com/23-tar-command-examples-for-linux/:
For example, we would change:
cp -R "$SpringDir"/. "$SlideShowDir"/
To:
tar -xf "$SpringDir"archive.tar -C "$SlideShowDir"/
... and so on for the other seasons.
Setup variables for season start
Using variables for season start days makes it easier to modify the script and makes the code easier to read (aka code readability).
Consider setting up Variables for start of season:
SpringStart=079
SummerStart=179
FallStart=265
WinterStart=355
Define the variables at the top of the script to make them easier to spot and change. You might want to do this for leap years. You might want to change to "Meteorological" season starts instead of "Astronomical" start dates.
Then change these lines:
if ((DOY>=079 && DOY<172)) ; then
elif ((DOY>=172 && DOY<265)) ; then
elif ((DOY>=265 && DOY<355)) ; then
To this:
if ((DOY>="$SpringStart" && DOY<"$SummerStart")) ; then
elif ((DOY>="$SummerStart" && DOY<"$FallStart")) ; then
elif ((DOY>="$FallStart" && DOY<"$WinterStart")) ; then
NOTE: I was hoping to finish this answer in an hour but it's been two hours and I have to do some Saturday Shopping. To Be Continued...
The basic question is how to do something at the start of Spring, Summer, Fall and Winter. For this I would create a bash script that runs on boot, rather than clogging up cron
with entries.
I've approached this answer using the OP's question "How do I develop a script?". So I've deviated from usual method of simply posting a bash script and enhanced the answer with:
- References are included within the code. They link to Stack Exchange answers for solving specific problems. For example: How to copy files, How to get day of year, etc.
- A section on "Testing" is provided as it is something we all need to do
- A section on "Enhancements" is provided because software is usually developed in versions where each is incrementally better than the previous version.
When do seasons start?
From the Farmer's Almanac:
Seasons of 2018
Season Astronomical Start Meteorological Start
====== ===================================== =====================
SPRING Tuesday, March 20, 12:15 P.M. EDT Thursday, March 1
SUMMER Thursday, June 21, 6:07 A.M. EDT Friday, June 1
FALL Saturday, September 22, 9:54 P.M. EDT Saturday, September 1
WINTER Friday, December 21, 5:23 P.M. EST Saturday, December 1
Convert season start date to Day of Year
For our bash
script to work we need to know what day of the year each seasons start.
$ echo $(date --date="March 20" '+%j')
079
$ echo $(date --date="June 21" '+%j')
172
$ echo $(date --date="Sep 22" '+%j')
265
$ echo $(date --date="Dec 21" '+%j')
355
# Reference: https://unix.stackexchange.com/questions/352176/take-input-arguments-and-pass-them-to-date
Create bash script: season.sh
Open the terminal using: Ctrl+Alt+T
Create the directory if it doesn't exist: mkdir -p ~/bin
Edit the script using: gedit ~/bin/season.sh
Note: Lubuntu user's need to useleafpad
instead ofgedit
Copy and paste the following lines into gedit
:
#!/bin/bash
# NAME: season.sh
# PATH: ~/bin
# DATE: December 15, 2018
# NOTE: Written for: https://askubuntu.com/questions/1100934/change-dynamic-wallpaper-directory-every-season/1102084#1102084
# User defined variables, change to suit your needs
# Our directory names, lines indented for cosmetic reasons only
SlideShowDir="~/Season Slide Show"
SpringDir="~/Pictures/Spring Slide Show"
SummerDir="~/Pictures/Summer Slide Show"
FallDir="~/Pictures/Fall Slide Show"
WinterDir="~/Pictures/Winter Slide Show"
CheckTripWire () {
# Our last season is in "~/Season Slide Show/CurrentSeason"
LastSeasonFilename="$SlideShowDir"/CurrentSeason
LastSeason=$(cat "$LastSeasonFilename")
[[ "$LastSeason" == "$Season" ]] && return 0 # Season still the same
# We now know our season has changed.
rm -f "$SlideShowDir"/{*,.*} # Erase all files in target
# Reference: https://askubuntu.com/questions/60228/how-to-remove-all-files-from-a-directory
echo "$Season" > "$LastSeasonFilename" # Record new season in target
# Copy new slide show based on season
if (( "$Season" == SPRING)) ; then
cp -R "$SpringDir"/. "$SlideShowDir"/
# Reference: https://stackoverflow.com/questions/3643848/copy-files-from-one-directory-into-an-existing-directory
elif (( "$Season" == SUMMER)) ; then
cp -R "$SummerDir"/. "$SlideShowDir"/
elif (( "$Season" == FALL)) ; then
cp -R "$FallDir"/. "$SlideShowDir"/
else
cp -R "$WinterDir"/. "$SlideShowDir"/
fi
} # End of CheckTripWire () function.
# Start of Mainline
DOY=$(date '+%j') # DOY = Current Day of Year
# Reference: https://stackoverflow.com/questions/10112453/how-to-get-day-of-the-year-in-shell
if ((DOY>=079 && DOY<172)) ; then
Season="SPRING" # Spring has sprung!
# Reference: https://stackoverflow.com/questions/12614011/using-case-for-a-range-of-numbers-in-bash
elif ((DOY>=172 && DOY<265)) ; then
Season="SUMMER" # Hit the beach!
elif ((DOY>=265 && DOY<355)) ; then
Season="FALL" # Rake those leaves!
else
Season="WINTER" # Shovel the snow!
fi
# Current season establish, now see if we tripped the wire
CheckTripWire
exit 0 # Command not necessary but good habit to signify no Abend.
Save the file in gedit
. Now mark it as executable using:
chmod a+x ~/bin/season.sh
Next we need to add it to startup applications. Reference: How do I start applications automatically on login?
Note: You probably already have your slide show setup in startup applications. You will want to use season.sh
BEFORE your regular slide show as it deletes and copies files which would crash the slide show program if it started first.
Testing
You will want to test season.sh
script when you create it and not wait a year to see if it works properly or not. Reference: https://serverfault.com/questions/138325/faking-the-date-for-a-specific-shell-session
Enhancements
After initially developing a script it is common to enhance it Days, Weeks, Months or even Years later. This section discusses some enhancements you might want to make to session.sh
down the road.
Compress files to save disk space
Consider keeping the off-season images compressed in TAR (Tape Archive) format to save on disk space. Then replace the cp
(Copy) command with the tar
command to un-compress the files. Reference: https://www.rootusers.com/23-tar-command-examples-for-linux/:
For example, we would change:
cp -R "$SpringDir"/. "$SlideShowDir"/
To:
tar -xf "$SpringDir"archive.tar -C "$SlideShowDir"/
... and so on for the other seasons.
Setup variables for season start
Using variables for season start days makes it easier to modify the script and makes the code easier to read (aka code readability).
Consider setting up Variables for start of season:
SpringStart=079
SummerStart=179
FallStart=265
WinterStart=355
Define the variables at the top of the script to make them easier to spot and change. You might want to do this for leap years. You might want to change to "Meteorological" season starts instead of "Astronomical" start dates.
Then change these lines:
if ((DOY>=079 && DOY<172)) ; then
elif ((DOY>=172 && DOY<265)) ; then
elif ((DOY>=265 && DOY<355)) ; then
To this:
if ((DOY>="$SpringStart" && DOY<"$SummerStart")) ; then
elif ((DOY>="$SummerStart" && DOY<"$FallStart")) ; then
elif ((DOY>="$FallStart" && DOY<"$WinterStart")) ; then
NOTE: I was hoping to finish this answer in an hour but it's been two hours and I have to do some Saturday Shopping. To Be Continued...
edited Dec 15 at 17:59
answered Dec 15 at 14:24
WinEunuuchs2Unix
41.7k1070158
41.7k1070158
very nice point @WinEunnuchs2Unix. you got the Question very clearly. i am eager to know how this script is useful in relation to Question. i am intrested to know, after getting DayOfYear by your script..how the system will change the wall paper. Thank You.
– PRATAP
Dec 15 at 14:47
@PRATAP I regret I didn't get the whole answer completely polished in two hours but enough is there to answer your comment I believe.
– WinEunuuchs2Unix
Dec 15 at 15:32
excellent coding... now i understood. Thank You.
– PRATAP
Dec 15 at 15:40
Thanks for the answer. I accepted this because 1) I needed to practice with bash and it was a great tutorial, and 2) It was really complete and well laid out. Utlimately, I combined it with @unutbu answer to just change a symbolic link instead of copying and pasting files. Here is a gist with the code. If you just want a simple method to do this without creating a script, I think @unutbu answer is probably the way to go.
– Joseph Gilgen
Dec 17 at 22:21
@JosephGilgen I agree the cron method is simplest and up-voted it. I approached the question as requiring a scripting answer with the objective of teaching a little scripting along the way. I included references to other Stack Exchange answers to show where the theory / implementation of different coding techniques come from. It was a thoroughly enjoyable project and I thank you for posting the question. Which I also hopes garners many upvotes :)
– WinEunuuchs2Unix
Dec 17 at 23:18
add a comment |
very nice point @WinEunnuchs2Unix. you got the Question very clearly. i am eager to know how this script is useful in relation to Question. i am intrested to know, after getting DayOfYear by your script..how the system will change the wall paper. Thank You.
– PRATAP
Dec 15 at 14:47
@PRATAP I regret I didn't get the whole answer completely polished in two hours but enough is there to answer your comment I believe.
– WinEunuuchs2Unix
Dec 15 at 15:32
excellent coding... now i understood. Thank You.
– PRATAP
Dec 15 at 15:40
Thanks for the answer. I accepted this because 1) I needed to practice with bash and it was a great tutorial, and 2) It was really complete and well laid out. Utlimately, I combined it with @unutbu answer to just change a symbolic link instead of copying and pasting files. Here is a gist with the code. If you just want a simple method to do this without creating a script, I think @unutbu answer is probably the way to go.
– Joseph Gilgen
Dec 17 at 22:21
@JosephGilgen I agree the cron method is simplest and up-voted it. I approached the question as requiring a scripting answer with the objective of teaching a little scripting along the way. I included references to other Stack Exchange answers to show where the theory / implementation of different coding techniques come from. It was a thoroughly enjoyable project and I thank you for posting the question. Which I also hopes garners many upvotes :)
– WinEunuuchs2Unix
Dec 17 at 23:18
very nice point @WinEunnuchs2Unix. you got the Question very clearly. i am eager to know how this script is useful in relation to Question. i am intrested to know, after getting DayOfYear by your script..how the system will change the wall paper. Thank You.
– PRATAP
Dec 15 at 14:47
very nice point @WinEunnuchs2Unix. you got the Question very clearly. i am eager to know how this script is useful in relation to Question. i am intrested to know, after getting DayOfYear by your script..how the system will change the wall paper. Thank You.
– PRATAP
Dec 15 at 14:47
@PRATAP I regret I didn't get the whole answer completely polished in two hours but enough is there to answer your comment I believe.
– WinEunuuchs2Unix
Dec 15 at 15:32
@PRATAP I regret I didn't get the whole answer completely polished in two hours but enough is there to answer your comment I believe.
– WinEunuuchs2Unix
Dec 15 at 15:32
excellent coding... now i understood. Thank You.
– PRATAP
Dec 15 at 15:40
excellent coding... now i understood. Thank You.
– PRATAP
Dec 15 at 15:40
Thanks for the answer. I accepted this because 1) I needed to practice with bash and it was a great tutorial, and 2) It was really complete and well laid out. Utlimately, I combined it with @unutbu answer to just change a symbolic link instead of copying and pasting files. Here is a gist with the code. If you just want a simple method to do this without creating a script, I think @unutbu answer is probably the way to go.
– Joseph Gilgen
Dec 17 at 22:21
Thanks for the answer. I accepted this because 1) I needed to practice with bash and it was a great tutorial, and 2) It was really complete and well laid out. Utlimately, I combined it with @unutbu answer to just change a symbolic link instead of copying and pasting files. Here is a gist with the code. If you just want a simple method to do this without creating a script, I think @unutbu answer is probably the way to go.
– Joseph Gilgen
Dec 17 at 22:21
@JosephGilgen I agree the cron method is simplest and up-voted it. I approached the question as requiring a scripting answer with the objective of teaching a little scripting along the way. I included references to other Stack Exchange answers to show where the theory / implementation of different coding techniques come from. It was a thoroughly enjoyable project and I thank you for posting the question. Which I also hopes garners many upvotes :)
– WinEunuuchs2Unix
Dec 17 at 23:18
@JosephGilgen I agree the cron method is simplest and up-voted it. I approached the question as requiring a scripting answer with the objective of teaching a little scripting along the way. I included references to other Stack Exchange answers to show where the theory / implementation of different coding techniques come from. It was a thoroughly enjoyable project and I thank you for posting the question. Which I also hopes garners many upvotes :)
– WinEunuuchs2Unix
Dec 17 at 23:18
add a comment |
Perhaps this is an easier way:
Create a symlink from
~/images/mybackgrounds
to~/images/spring
:
ln -s ~/images/spring ~/images/mybackgrounds
Use one of these methods to display a background slideshow using images from
~/images/mybackgrounds
.
Set up crontab entries to change the symlink on particular days. Create a file called
~/mycrontab
with these contents:
# min hr day mon dow
0 9 21 3 * ln -sf ~/images/spring ~/images/mybackgrounds
0 9 21 6 * ln -sf ~/images/summer ~/images/mybackgrounds
0 9 21 9 * ln -sf ~/images/fall ~/images/mybackgrounds
0 9 21 12 * ln -sf ~/images/winter ~/images/mybackgrounds
Run
crontab ~/mycrontab
to register the crontab entries. On March 21 at 9AM,
crond
will run the command
ln -sf ~/images/spring ~/images/mybackgrounds
thus linking ~/images/mybackgrounds
to ~/images/spring
. On Jun 21 at 9AM,
crond
will change the symlink so that ~/images/mybackgrounds
points to
~/images/summer
. The slideshow program is configured to select a file from
~/images/mybackgrounds
. The path to ~/images/mybackgrounds
stays the same,
but now all the contents are different because the symlink points to a different
location. The crontab entries for Sep 21 and Dec 21 pull the same trick.
This is really the most simple and straight forward method to accomplish what I was trying to do. No scripting, just updating the slideshow directory with a cron job. While I accepted the answer from @WinEunuuchs2Unix, perhaps upvotes will really show this to be the most useful answer.
– Joseph Gilgen
Dec 17 at 22:24
Upvote from me :)
– WinEunuuchs2Unix
Dec 17 at 23:15
add a comment |
Perhaps this is an easier way:
Create a symlink from
~/images/mybackgrounds
to~/images/spring
:
ln -s ~/images/spring ~/images/mybackgrounds
Use one of these methods to display a background slideshow using images from
~/images/mybackgrounds
.
Set up crontab entries to change the symlink on particular days. Create a file called
~/mycrontab
with these contents:
# min hr day mon dow
0 9 21 3 * ln -sf ~/images/spring ~/images/mybackgrounds
0 9 21 6 * ln -sf ~/images/summer ~/images/mybackgrounds
0 9 21 9 * ln -sf ~/images/fall ~/images/mybackgrounds
0 9 21 12 * ln -sf ~/images/winter ~/images/mybackgrounds
Run
crontab ~/mycrontab
to register the crontab entries. On March 21 at 9AM,
crond
will run the command
ln -sf ~/images/spring ~/images/mybackgrounds
thus linking ~/images/mybackgrounds
to ~/images/spring
. On Jun 21 at 9AM,
crond
will change the symlink so that ~/images/mybackgrounds
points to
~/images/summer
. The slideshow program is configured to select a file from
~/images/mybackgrounds
. The path to ~/images/mybackgrounds
stays the same,
but now all the contents are different because the symlink points to a different
location. The crontab entries for Sep 21 and Dec 21 pull the same trick.
This is really the most simple and straight forward method to accomplish what I was trying to do. No scripting, just updating the slideshow directory with a cron job. While I accepted the answer from @WinEunuuchs2Unix, perhaps upvotes will really show this to be the most useful answer.
– Joseph Gilgen
Dec 17 at 22:24
Upvote from me :)
– WinEunuuchs2Unix
Dec 17 at 23:15
add a comment |
Perhaps this is an easier way:
Create a symlink from
~/images/mybackgrounds
to~/images/spring
:
ln -s ~/images/spring ~/images/mybackgrounds
Use one of these methods to display a background slideshow using images from
~/images/mybackgrounds
.
Set up crontab entries to change the symlink on particular days. Create a file called
~/mycrontab
with these contents:
# min hr day mon dow
0 9 21 3 * ln -sf ~/images/spring ~/images/mybackgrounds
0 9 21 6 * ln -sf ~/images/summer ~/images/mybackgrounds
0 9 21 9 * ln -sf ~/images/fall ~/images/mybackgrounds
0 9 21 12 * ln -sf ~/images/winter ~/images/mybackgrounds
Run
crontab ~/mycrontab
to register the crontab entries. On March 21 at 9AM,
crond
will run the command
ln -sf ~/images/spring ~/images/mybackgrounds
thus linking ~/images/mybackgrounds
to ~/images/spring
. On Jun 21 at 9AM,
crond
will change the symlink so that ~/images/mybackgrounds
points to
~/images/summer
. The slideshow program is configured to select a file from
~/images/mybackgrounds
. The path to ~/images/mybackgrounds
stays the same,
but now all the contents are different because the symlink points to a different
location. The crontab entries for Sep 21 and Dec 21 pull the same trick.
Perhaps this is an easier way:
Create a symlink from
~/images/mybackgrounds
to~/images/spring
:
ln -s ~/images/spring ~/images/mybackgrounds
Use one of these methods to display a background slideshow using images from
~/images/mybackgrounds
.
Set up crontab entries to change the symlink on particular days. Create a file called
~/mycrontab
with these contents:
# min hr day mon dow
0 9 21 3 * ln -sf ~/images/spring ~/images/mybackgrounds
0 9 21 6 * ln -sf ~/images/summer ~/images/mybackgrounds
0 9 21 9 * ln -sf ~/images/fall ~/images/mybackgrounds
0 9 21 12 * ln -sf ~/images/winter ~/images/mybackgrounds
Run
crontab ~/mycrontab
to register the crontab entries. On March 21 at 9AM,
crond
will run the command
ln -sf ~/images/spring ~/images/mybackgrounds
thus linking ~/images/mybackgrounds
to ~/images/spring
. On Jun 21 at 9AM,
crond
will change the symlink so that ~/images/mybackgrounds
points to
~/images/summer
. The slideshow program is configured to select a file from
~/images/mybackgrounds
. The path to ~/images/mybackgrounds
stays the same,
but now all the contents are different because the symlink points to a different
location. The crontab entries for Sep 21 and Dec 21 pull the same trick.
edited Dec 15 at 3:22
answered Dec 15 at 3:11
unutbu
867917
867917
This is really the most simple and straight forward method to accomplish what I was trying to do. No scripting, just updating the slideshow directory with a cron job. While I accepted the answer from @WinEunuuchs2Unix, perhaps upvotes will really show this to be the most useful answer.
– Joseph Gilgen
Dec 17 at 22:24
Upvote from me :)
– WinEunuuchs2Unix
Dec 17 at 23:15
add a comment |
This is really the most simple and straight forward method to accomplish what I was trying to do. No scripting, just updating the slideshow directory with a cron job. While I accepted the answer from @WinEunuuchs2Unix, perhaps upvotes will really show this to be the most useful answer.
– Joseph Gilgen
Dec 17 at 22:24
Upvote from me :)
– WinEunuuchs2Unix
Dec 17 at 23:15
This is really the most simple and straight forward method to accomplish what I was trying to do. No scripting, just updating the slideshow directory with a cron job. While I accepted the answer from @WinEunuuchs2Unix, perhaps upvotes will really show this to be the most useful answer.
– Joseph Gilgen
Dec 17 at 22:24
This is really the most simple and straight forward method to accomplish what I was trying to do. No scripting, just updating the slideshow directory with a cron job. While I accepted the answer from @WinEunuuchs2Unix, perhaps upvotes will really show this to be the most useful answer.
– Joseph Gilgen
Dec 17 at 22:24
Upvote from me :)
– WinEunuuchs2Unix
Dec 17 at 23:15
Upvote from me :)
– WinEunuuchs2Unix
Dec 17 at 23:15
add a comment |
Step 1: Create a slideshow.py script
Save this in a file called ~/bin/slideshow.py
:
#!/usr/bin/env python
import os
import datetime as DT
import itertools as IT
import bisect
import random
import subprocess
# customize cutoffs and image_dirs however you like, but note that there must be
# the same number of items in each, and the items in cutoffs must be in sorted order.
cutoffs = [(3, 21), (6, 21), (9, 21), (12, 21)]
image_dirs = ['~/images/winter', '~/images/spring', '~/images/summer', '~/images/fall']
image_dirs = list(map(os.path.expanduser, image_dirs))
today = DT.date.today()
year = today.year
# convert the cutoffs to actual dates
cutoff_dates = [DT.date(year, m, d) for m, d in cutoffs]
# find the index into cutoff_dates where today would fit and still keep the list sorted
idx = bisect.bisect(cutoff_dates, today)
# use idx to get the corresponding image directory
image_dir = next(IT.islice(IT.cycle(image_dirs), idx, idx+1))
# list all the files in image_dir (even in subdirectories, and following symlinks)
files = [os.path.join(root, filename)
for root, dirs, files in os.walk(image_dirs[idx], followlinks=True)
for filename in files]
# pick a file at random
imagefile = os.path.abspath(random.choice(files))
# find the current process's effective user id (EUID)
euid = str(os.geteuid())
# find the pid of the current EUID's gnome-session
pid = subprocess.check_output(['pgrep', '--euid', euid, 'gnome-session']).strip().decode()
# load all the environment variables of gnome-session
env = open('/proc/{}/environ'.format(pid), 'rb').read().strip(b'x00')
env = dict([item.split(b'=', 1) for item in env.split(b'x00')])
# get the value of DBUS_SESSION_BUS_ADDRESS environment variable
key = b'DBUS_SESSION_BUS_ADDRESS'
env = {key: env[key]}
# call gsettings to change the background to display the selected file
# with the DBUS_SESSION_BUS_ADDRESS environment variable set appropriately
subprocess.call(['gsettings', 'set', 'org.gnome.desktop.background', 'picture-uri',
'file://{}'.format(imagefile)], env=env)
Step 2: Make it executable:
chmod 755 ~/bin/slideshow.py
To test that things are working as expected, you can open a terminal and run
slideshow.py
repeatedly. You should see the background changing. Note that
slideshow.py
looks for images in one of 4 directories, ~/images/spring
,
~/images/summer
, ~/images/fall
, or ~/images/winter
depending on the season.
Step 3: Configure crontab
You can use cron to periodically
run a command to change the background, say, once every day or once every minute
minutes.
Make a file called, say, ~/mycrontab
, and
put something like this inside:
# min hr day mon dow
# 0 9 * * * ~/bin/slideshow.py # run once at 9AM
* * * * * ~/bin/slideshow.py # run once every minute
Then run
crontab ~/mycrontab
to register the change to your crontab.
You should now see the background changing once every minute. (You might even enjoy keeping it this way.)
crontab
will ignore lines which begin with #
. So if you want the background
to change once per day, uncomment the second line and comment-out the third so
that ~/mycrontab
now looks like this:
# min hr day mon dow
0 9 * * * ~/bin/slideshow.py # run once at 9AM
# * * * * * ~/bin/slideshow.py # run once every minute
Note however that cron will only run this command if you are logged into the machine
at 9AM that day.
I like the direction this is going. I have not had a chance to play with it yet. What I am trying to do though is change the directory every season, so it would be something like/path/to/spring/*.png
in spring, but I don't quite think that would work.
– Joseph Gilgen
Dec 14 at 22:29
Hope you don't mind but I edited your answer to use Python Language highlighting. I also changedchown
tochmod
which I think was your original intent.
– WinEunuuchs2Unix
Dec 15 at 18:18
@WinEunuuchs2Unix: Thanks for the corrections.
– unutbu
Dec 15 at 18:20
add a comment |
Step 1: Create a slideshow.py script
Save this in a file called ~/bin/slideshow.py
:
#!/usr/bin/env python
import os
import datetime as DT
import itertools as IT
import bisect
import random
import subprocess
# customize cutoffs and image_dirs however you like, but note that there must be
# the same number of items in each, and the items in cutoffs must be in sorted order.
cutoffs = [(3, 21), (6, 21), (9, 21), (12, 21)]
image_dirs = ['~/images/winter', '~/images/spring', '~/images/summer', '~/images/fall']
image_dirs = list(map(os.path.expanduser, image_dirs))
today = DT.date.today()
year = today.year
# convert the cutoffs to actual dates
cutoff_dates = [DT.date(year, m, d) for m, d in cutoffs]
# find the index into cutoff_dates where today would fit and still keep the list sorted
idx = bisect.bisect(cutoff_dates, today)
# use idx to get the corresponding image directory
image_dir = next(IT.islice(IT.cycle(image_dirs), idx, idx+1))
# list all the files in image_dir (even in subdirectories, and following symlinks)
files = [os.path.join(root, filename)
for root, dirs, files in os.walk(image_dirs[idx], followlinks=True)
for filename in files]
# pick a file at random
imagefile = os.path.abspath(random.choice(files))
# find the current process's effective user id (EUID)
euid = str(os.geteuid())
# find the pid of the current EUID's gnome-session
pid = subprocess.check_output(['pgrep', '--euid', euid, 'gnome-session']).strip().decode()
# load all the environment variables of gnome-session
env = open('/proc/{}/environ'.format(pid), 'rb').read().strip(b'x00')
env = dict([item.split(b'=', 1) for item in env.split(b'x00')])
# get the value of DBUS_SESSION_BUS_ADDRESS environment variable
key = b'DBUS_SESSION_BUS_ADDRESS'
env = {key: env[key]}
# call gsettings to change the background to display the selected file
# with the DBUS_SESSION_BUS_ADDRESS environment variable set appropriately
subprocess.call(['gsettings', 'set', 'org.gnome.desktop.background', 'picture-uri',
'file://{}'.format(imagefile)], env=env)
Step 2: Make it executable:
chmod 755 ~/bin/slideshow.py
To test that things are working as expected, you can open a terminal and run
slideshow.py
repeatedly. You should see the background changing. Note that
slideshow.py
looks for images in one of 4 directories, ~/images/spring
,
~/images/summer
, ~/images/fall
, or ~/images/winter
depending on the season.
Step 3: Configure crontab
You can use cron to periodically
run a command to change the background, say, once every day or once every minute
minutes.
Make a file called, say, ~/mycrontab
, and
put something like this inside:
# min hr day mon dow
# 0 9 * * * ~/bin/slideshow.py # run once at 9AM
* * * * * ~/bin/slideshow.py # run once every minute
Then run
crontab ~/mycrontab
to register the change to your crontab.
You should now see the background changing once every minute. (You might even enjoy keeping it this way.)
crontab
will ignore lines which begin with #
. So if you want the background
to change once per day, uncomment the second line and comment-out the third so
that ~/mycrontab
now looks like this:
# min hr day mon dow
0 9 * * * ~/bin/slideshow.py # run once at 9AM
# * * * * * ~/bin/slideshow.py # run once every minute
Note however that cron will only run this command if you are logged into the machine
at 9AM that day.
I like the direction this is going. I have not had a chance to play with it yet. What I am trying to do though is change the directory every season, so it would be something like/path/to/spring/*.png
in spring, but I don't quite think that would work.
– Joseph Gilgen
Dec 14 at 22:29
Hope you don't mind but I edited your answer to use Python Language highlighting. I also changedchown
tochmod
which I think was your original intent.
– WinEunuuchs2Unix
Dec 15 at 18:18
@WinEunuuchs2Unix: Thanks for the corrections.
– unutbu
Dec 15 at 18:20
add a comment |
Step 1: Create a slideshow.py script
Save this in a file called ~/bin/slideshow.py
:
#!/usr/bin/env python
import os
import datetime as DT
import itertools as IT
import bisect
import random
import subprocess
# customize cutoffs and image_dirs however you like, but note that there must be
# the same number of items in each, and the items in cutoffs must be in sorted order.
cutoffs = [(3, 21), (6, 21), (9, 21), (12, 21)]
image_dirs = ['~/images/winter', '~/images/spring', '~/images/summer', '~/images/fall']
image_dirs = list(map(os.path.expanduser, image_dirs))
today = DT.date.today()
year = today.year
# convert the cutoffs to actual dates
cutoff_dates = [DT.date(year, m, d) for m, d in cutoffs]
# find the index into cutoff_dates where today would fit and still keep the list sorted
idx = bisect.bisect(cutoff_dates, today)
# use idx to get the corresponding image directory
image_dir = next(IT.islice(IT.cycle(image_dirs), idx, idx+1))
# list all the files in image_dir (even in subdirectories, and following symlinks)
files = [os.path.join(root, filename)
for root, dirs, files in os.walk(image_dirs[idx], followlinks=True)
for filename in files]
# pick a file at random
imagefile = os.path.abspath(random.choice(files))
# find the current process's effective user id (EUID)
euid = str(os.geteuid())
# find the pid of the current EUID's gnome-session
pid = subprocess.check_output(['pgrep', '--euid', euid, 'gnome-session']).strip().decode()
# load all the environment variables of gnome-session
env = open('/proc/{}/environ'.format(pid), 'rb').read().strip(b'x00')
env = dict([item.split(b'=', 1) for item in env.split(b'x00')])
# get the value of DBUS_SESSION_BUS_ADDRESS environment variable
key = b'DBUS_SESSION_BUS_ADDRESS'
env = {key: env[key]}
# call gsettings to change the background to display the selected file
# with the DBUS_SESSION_BUS_ADDRESS environment variable set appropriately
subprocess.call(['gsettings', 'set', 'org.gnome.desktop.background', 'picture-uri',
'file://{}'.format(imagefile)], env=env)
Step 2: Make it executable:
chmod 755 ~/bin/slideshow.py
To test that things are working as expected, you can open a terminal and run
slideshow.py
repeatedly. You should see the background changing. Note that
slideshow.py
looks for images in one of 4 directories, ~/images/spring
,
~/images/summer
, ~/images/fall
, or ~/images/winter
depending on the season.
Step 3: Configure crontab
You can use cron to periodically
run a command to change the background, say, once every day or once every minute
minutes.
Make a file called, say, ~/mycrontab
, and
put something like this inside:
# min hr day mon dow
# 0 9 * * * ~/bin/slideshow.py # run once at 9AM
* * * * * ~/bin/slideshow.py # run once every minute
Then run
crontab ~/mycrontab
to register the change to your crontab.
You should now see the background changing once every minute. (You might even enjoy keeping it this way.)
crontab
will ignore lines which begin with #
. So if you want the background
to change once per day, uncomment the second line and comment-out the third so
that ~/mycrontab
now looks like this:
# min hr day mon dow
0 9 * * * ~/bin/slideshow.py # run once at 9AM
# * * * * * ~/bin/slideshow.py # run once every minute
Note however that cron will only run this command if you are logged into the machine
at 9AM that day.
Step 1: Create a slideshow.py script
Save this in a file called ~/bin/slideshow.py
:
#!/usr/bin/env python
import os
import datetime as DT
import itertools as IT
import bisect
import random
import subprocess
# customize cutoffs and image_dirs however you like, but note that there must be
# the same number of items in each, and the items in cutoffs must be in sorted order.
cutoffs = [(3, 21), (6, 21), (9, 21), (12, 21)]
image_dirs = ['~/images/winter', '~/images/spring', '~/images/summer', '~/images/fall']
image_dirs = list(map(os.path.expanduser, image_dirs))
today = DT.date.today()
year = today.year
# convert the cutoffs to actual dates
cutoff_dates = [DT.date(year, m, d) for m, d in cutoffs]
# find the index into cutoff_dates where today would fit and still keep the list sorted
idx = bisect.bisect(cutoff_dates, today)
# use idx to get the corresponding image directory
image_dir = next(IT.islice(IT.cycle(image_dirs), idx, idx+1))
# list all the files in image_dir (even in subdirectories, and following symlinks)
files = [os.path.join(root, filename)
for root, dirs, files in os.walk(image_dirs[idx], followlinks=True)
for filename in files]
# pick a file at random
imagefile = os.path.abspath(random.choice(files))
# find the current process's effective user id (EUID)
euid = str(os.geteuid())
# find the pid of the current EUID's gnome-session
pid = subprocess.check_output(['pgrep', '--euid', euid, 'gnome-session']).strip().decode()
# load all the environment variables of gnome-session
env = open('/proc/{}/environ'.format(pid), 'rb').read().strip(b'x00')
env = dict([item.split(b'=', 1) for item in env.split(b'x00')])
# get the value of DBUS_SESSION_BUS_ADDRESS environment variable
key = b'DBUS_SESSION_BUS_ADDRESS'
env = {key: env[key]}
# call gsettings to change the background to display the selected file
# with the DBUS_SESSION_BUS_ADDRESS environment variable set appropriately
subprocess.call(['gsettings', 'set', 'org.gnome.desktop.background', 'picture-uri',
'file://{}'.format(imagefile)], env=env)
Step 2: Make it executable:
chmod 755 ~/bin/slideshow.py
To test that things are working as expected, you can open a terminal and run
slideshow.py
repeatedly. You should see the background changing. Note that
slideshow.py
looks for images in one of 4 directories, ~/images/spring
,
~/images/summer
, ~/images/fall
, or ~/images/winter
depending on the season.
Step 3: Configure crontab
You can use cron to periodically
run a command to change the background, say, once every day or once every minute
minutes.
Make a file called, say, ~/mycrontab
, and
put something like this inside:
# min hr day mon dow
# 0 9 * * * ~/bin/slideshow.py # run once at 9AM
* * * * * ~/bin/slideshow.py # run once every minute
Then run
crontab ~/mycrontab
to register the change to your crontab.
You should now see the background changing once every minute. (You might even enjoy keeping it this way.)
crontab
will ignore lines which begin with #
. So if you want the background
to change once per day, uncomment the second line and comment-out the third so
that ~/mycrontab
now looks like this:
# min hr day mon dow
0 9 * * * ~/bin/slideshow.py # run once at 9AM
# * * * * * ~/bin/slideshow.py # run once every minute
Note however that cron will only run this command if you are logged into the machine
at 9AM that day.
edited Dec 15 at 18:18
WinEunuuchs2Unix
41.7k1070158
41.7k1070158
answered Dec 14 at 17:54
unutbu
867917
867917
I like the direction this is going. I have not had a chance to play with it yet. What I am trying to do though is change the directory every season, so it would be something like/path/to/spring/*.png
in spring, but I don't quite think that would work.
– Joseph Gilgen
Dec 14 at 22:29
Hope you don't mind but I edited your answer to use Python Language highlighting. I also changedchown
tochmod
which I think was your original intent.
– WinEunuuchs2Unix
Dec 15 at 18:18
@WinEunuuchs2Unix: Thanks for the corrections.
– unutbu
Dec 15 at 18:20
add a comment |
I like the direction this is going. I have not had a chance to play with it yet. What I am trying to do though is change the directory every season, so it would be something like/path/to/spring/*.png
in spring, but I don't quite think that would work.
– Joseph Gilgen
Dec 14 at 22:29
Hope you don't mind but I edited your answer to use Python Language highlighting. I also changedchown
tochmod
which I think was your original intent.
– WinEunuuchs2Unix
Dec 15 at 18:18
@WinEunuuchs2Unix: Thanks for the corrections.
– unutbu
Dec 15 at 18:20
I like the direction this is going. I have not had a chance to play with it yet. What I am trying to do though is change the directory every season, so it would be something like
/path/to/spring/*.png
in spring, but I don't quite think that would work.– Joseph Gilgen
Dec 14 at 22:29
I like the direction this is going. I have not had a chance to play with it yet. What I am trying to do though is change the directory every season, so it would be something like
/path/to/spring/*.png
in spring, but I don't quite think that would work.– Joseph Gilgen
Dec 14 at 22:29
Hope you don't mind but I edited your answer to use Python Language highlighting. I also changed
chown
to chmod
which I think was your original intent.– WinEunuuchs2Unix
Dec 15 at 18:18
Hope you don't mind but I edited your answer to use Python Language highlighting. I also changed
chown
to chmod
which I think was your original intent.– WinEunuuchs2Unix
Dec 15 at 18:18
@WinEunuuchs2Unix: Thanks for the corrections.
– unutbu
Dec 15 at 18:20
@WinEunuuchs2Unix: Thanks for the corrections.
– unutbu
Dec 15 at 18:20
add a comment |
Joseph Gilgen is a new contributor. Be nice, and check out our Code of Conduct.
Joseph Gilgen is a new contributor. Be nice, and check out our Code of Conduct.
Joseph Gilgen is a new contributor. Be nice, and check out our Code of Conduct.
Joseph Gilgen is a new contributor. Be nice, and check out our Code of Conduct.
Thanks for contributing an answer to Ask Ubuntu!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1100934%2fchange-dynamic-wallpaper-directory-every-season%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
do you have your wall papers and folders ready? how many wallpapers in each of 4 seasonal folders.
– PRATAP
Dec 14 at 17:23
what is your Ubuntu version that you are going to do this on?
– PRATAP
Dec 14 at 17:24
Voting to Leave Open This question is more about scripting based on today's date and seasons of the year.
– WinEunuuchs2Unix
Dec 15 at 18:09