Go Si Mac
Introduction
GoSiMac downloads Bing's daily wallpapers, Unsplash's random images, etc. for you to have a beautiful wallpaper on your desktop whenever you want.
Personally, I wrote this to have fun and help one of my friends who are not among us right now. 😞
Usage
gosimac rev-4cbe101-dirty
Fetch the wallpaper from Bings, Unsplash...
Usage:
GoSiMac [command]
Available Commands:
bing fetches images from https://bing.com
completion Generate the autocompletion script for the specified shell
help Help about any command
unsplash fetches images from https://unsplash.org
Flags:
-h, --help help for GoSiMac
-p, --path string A path to where photos are stored (default "/home/parham/Pictures/GoSiMac")
Use "GoSiMac [command] --help" for more information about a command.
As an example, the following command downloads 10 images from unsplash while using Tehran as a search query.
Please note that the proxy setup is related to Iranian sanctions and you may not need to setup any proxy
to use gosimac.
export http_proxy="http://127.0.0.1:1080"
export https_proxy="http://127.0.0.1:1080"
gosimac u -q Tehran -n 10
set http_proxy "http://127.0.0.1:1080"
set https_proxy "http://127.0.0.1:1080"
$env:HTTP_PROXY = "http://127.0.0.1:1080"
$env:HTTPS_PROXY = "http://127.0.0.1:1080"
gosimac u -q Tehran -n 10
By default, gosimac stores images in $XDG_PICTURES_DIR/GoSiMac (e.g. $HOME/Pictures/GoSiMac).
Setting the wallpaper (macOS)
Pass the --set flag to any command and gosimac will pick one of the images it
just downloaded (at random) and set it as your desktop wallpaper. If the run brought
nothing new down, it falls back to the images already in your library. This is
currently supported on macOS; on other operating systems the flag is a no-op that
reports it is unsupported.
macOS keeps a separate wallpaper setting for every space, and for every display
within a space. gosimac writes them all, so the image applies across all your
spaces and monitors rather than only the one you happen to be looking at. On macOS
Sonoma and later this means rewriting ~/Library/Application Support/com.apple.wallpaper
and restarting WallpaperAgent; on older releases it falls back to osascript.
gosimac bing --set # download today's Bing wallpaper and apply it
gosimac u -q Tehran -n 10 --set
Contribution
For adding new source you only need to create a new sub-command in cmd package
and then calling your new source with provided path. Also for saving images
you can use the following helper function:
func (u *Unsplash) Store(name string, content io.ReadCloser) {
path := path.Join(
u.Path,
fmt.Sprintf("%s-%s.jpg", u.Prefix, name),
)
if _, err := os.Stat(path); err == nil {
pterm.Warning.Printf("%s is already exists\n", path)
return
}
file, err := os.Create(path)
if err != nil {
pterm.Error.Printf("os.Create: %v\n", err)
return
}
bytes, err := io.Copy(file, content)
if err != nil {
pterm.Error.Printf("io.Copy (%d bytes): %v\n", bytes, err)
}
if err := file.Close(); err != nil {
pterm.Error.Printf("(*os.File).Close: %v", err)
}
if err := content.Close(); err != nil {
pterm.Error.Printf("(*io.ReadCloser).Close: %v", err)
}
}