You are not logged in.

#1 2014-12-08 17:45:16

lmm5247
Member
Registered: 2014-09-01
Posts: 5

Bash script to use Bing’s background as wallpaper

Hey all,

Arch newbie here. Can't believe I didn't switch to Arch sooner. I wrote a small script to wget Bing's picture of the day and set it as a wallpaper with feh.

Blog post is here
http://www.loganmarchione.com/?p=1767

GitHub is here
https://github.com/loganmarchione/wallscript

Any recommendations to improve would be greatly appreciated!

Offline

#2 2014-12-08 17:49:27

ewaller
Administrator
From: Pasadena, CA
Registered: 2009-07-13
Posts: 20,334

Re: Bash script to use Bing’s background as wallpaper

Welcome to Arch.

Moving this thread to community contributions


Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Sometimes it is the people no one can imagine anything of who do the things no one can imagine. -- Alan Turing
---
How to Ask Questions the Smart Way

Offline

#3 2014-12-08 17:54:52

lmm5247
Member
Registered: 2014-09-01
Posts: 5

Re: Bash script to use Bing’s background as wallpaper

ewaller wrote:

Welcome to Arch.

Moving this thread to community contributions

Thanks! I had a feeling it was in the wrong place.

Offline

#4 2014-12-08 19:11:49

oliver
Member
Registered: 2007-12-12
Posts: 448

Re: Bash script to use Bing’s background as wallpaper

lmm5247 wrote:

Any recommendations to improve would be greatly appreciated!

Just an idea but you have the wallpaper directory defined as follows

directory=~/wallpapers/bing/

You could do something like:

directory="${1:-~/wallpapers/bing/}"

This mean that the directory would be ~/wallpapers/bing unless someone specified a different directory at the command line.  This is easier to explain with an example:

$ cat wp.sh 
#!/bin/bash

directory="${1:-~/wallpapers/bing/}"

echo $directory
$ ./wp.sh 
~/wallpapers/bing/

$ ./wp.sh /i/want/my/own/dir
/i/want/my/own/dir

If you want to do something like this, you should probably enclose the dir in quotes (to allow for spaces etc) and add the -p flag to mkdir

Last edited by oliver (2014-12-08 19:14:47)

Offline

#5 2014-12-08 20:30:07

lmm5247
Member
Registered: 2014-09-01
Posts: 5

Re: Bash script to use Bing’s background as wallpaper

oliver wrote:
lmm5247 wrote:

Any recommendations to improve would be greatly appreciated!

Just an idea but you have the wallpaper directory defined as follows

directory=~/wallpapers/bing/

You could do something like:

directory="${1:-~/wallpapers/bing/}"

This mean that the directory would be ~/wallpapers/bing unless someone specified a different directory at the command line.  This is easier to explain with an example:

$ cat wp.sh 
#!/bin/bash

directory="${1:-~/wallpapers/bing/}"

echo $directory
$ ./wp.sh 
~/wallpapers/bing/

$ ./wp.sh /i/want/my/own/dir
/i/want/my/own/dir

If you want to do something like this, you should probably enclose the dir in quotes (to allow for spaces etc) and add the -p flag to mkdir

Thanks! I didn't know you could do that!

Offline

#6 2014-12-08 20:55:55

oliver
Member
Registered: 2007-12-12
Posts: 448

Re: Bash script to use Bing’s background as wallpaper

lmm5247 wrote:

Thanks! I didn't know you could do that!

It may be overkill for what you plan (since you're probably editing the script for other stuff anyway) but it's definitely a nice thing to know.  I *think* it's bash 4.x only BTW (but I'm usually wrong)

Offline

#7 2014-12-08 21:45:56

alphaniner
Member
From: Ancapistan
Registered: 2010-07-12
Posts: 2,810

Re: Bash script to use Bing’s background as wallpaper

FWIW, that parameter expansion worked in bash 3.2.39.


But whether the Constitution really be one thing, or another, this much is certain - that it has either authorized such a government as we have had, or has been powerless to prevent it. In either case, it is unfit to exist.
-Lysander Spooner

Offline

Board footer

Powered by FluxBB