Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MacOS enhancements for desktop and screen saver #43

Open
Mike-BITW opened this issue May 27, 2019 · 0 comments
Open

MacOS enhancements for desktop and screen saver #43

Mike-BITW opened this issue May 27, 2019 · 0 comments

Comments

@Mike-BITW
Copy link

Mike-BITW commented May 27, 2019

MacOS Background and Screensaver

Using this "reddit-background" script as a starting point, you can display those wonderful reddit nature wallpapers for both desktop and screensaver automagically with a few "enhancements". Tested under Mojave, single display, survives sleep, no Internet, and flaky "StartInterval" quirks. Sorry about the sloppy coding, this is work in progress. A launchd job runs every 15 minutes and if the backgrounds are more than 6 hours old (or missing), it grabs a new set of 5 images. The current set is used for desktop backgrounds. The previous set is saved and both sets are used for the screensaver. Set it up once, then forget it. No promises, no guarantees, no support... 😇

1. ~/.reddit_background.conf:

[default]
subreddits=EarthPorn:new:50:month
#image_chooser=bestmatch
image_count=5

2. /usr/local/bin/get_wallpaper.sh

#!/bin/bash
if [[ -z $(find ~/Reddit\ Backgrounds/Desktop\ 1 -type f -mmin +360 2>/dev/null) ]]; then 
    # backgrounds are recent enough
	exit 0
else	
	/usr/local/bin/wget -q --tries=10 --timeout=20 --no-check-certificate --spider http://reddit.com >/dev/null 2>&1
    # check if reddit is available
	if [[ $? -eq 0 ]]; then
        # save current backgrounds
        ditto ~/Reddit\ Backgrounds/Desktop\ 1/ ~/Reddit\ Backgrounds\ Screensaver/ >/dev/null 2>&1
        # get new backgrounds
        /usr/local/bin/reddit-background >/dev/null 2>&1
        # check for portrait
		for file in ~/Reddit\ Backgrounds/Desktop\ 1/*
			do
				h=`sips -g pixelHeight "${file}" | tail -n1 | cut -d" " -f4`
				w=`sips -g pixelWidth "${file}" | tail -n1 | cut -d" " -f4`
				if [[ $h -gt $w ]] ; then
					# crop to square
					sips  -c $w  $w "${file}" >/dev/null 2>&1	
				fi
			done      
		# move old pics to screensaver
		mv -f ~/Reddit\ Backgrounds\ Screensaver/ ~/Reddit\ Backgrounds/Screensaver/ >/dev/null 2>&1	
                osascript -e 'display notification "Updated  " & (current date) & "." with title "Background Pictures"' >/dev/null 2>&1	
	fi
fi
exit 0 ;

3. ~/Library/LaunchAgents/update_wallpaper.plist:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>Disabled</key>
	<false/>
	<key>Label</key>
	<string>update_wallpaper</string>
	<key>Program</key>
	<string>/usr/local/bin/get_wallpaper.sh</string>
	<key>RunAtLoad</key>
	<true/>
	<key>StandardErrorPath</key>
	<string>dev/null</string>
	<key>StandardOutPath</key>
	<string>dev/null</string>
	<key>StartInterval</key>
	<integer>900</integer>
</dict>
</plist>

4. System Preferences -> Desktop & Screen Saver -> Desktop

  • Fill Screen
  • Random Order
  • Every 5 Minutes
  • Folder: "~/Reddit Backgrounds/Desktop 1"

5. System Preferences -> Desktop & Screen Saver -> Screen Saver

6. /Applications/wallpaper.command:

(optional app, based on /usr/local/bin/get_wallpaper.sh)

#!/bin/bash 
# see /usr/local/bin/get_wallpaper.sh
/usr/local/bin/wget -q --tries=10 --timeout=20 --no-check-certificate --spider http://reddit.com >/dev/null 2>&1
# check if reddit is available
if [[ $? -eq 0 ]]; then
    # save current backgrounds
    ditto ~/Reddit\ Backgrounds/Desktop\ 1/ ~/Reddit\ Backgrounds\ Screensaver/ >/dev/null 2>&1
    # get new backgrounds
    /usr/local/bin/reddit-background >/dev/null 2>&1
   # check for portrait
	for file in ~/Reddit\ Backgrounds/Desktop\ 1/*
		do
			h=`sips -g pixelHeight "${file}" | tail -n1 | cut -d" " -f4`
			w=`sips -g pixelWidth "${file}" | tail -n1 | cut -d" " -f4`
			if [[ $h -gt $w ]] ; then
				# crop to square
				sips  -c $w  $w "${file}" >/dev/null 2>&1	
			fi
		done      
	# move old pics to screensaver
	mv -f ~/Reddit\ Backgrounds\ Screensaver/ ~/Reddit\ Backgrounds/Screensaver/ >/dev/null 2>&1	
fi
       osascript -e 'display notification "Updated  " & (current date) & "." with title "Background Pictures"' >/dev/null 2>&1	
kill -9 $(ps -p $(ps -p $PPID -o ppid=) -o ppid=)
exit 0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant