Skip to content

Instantly share code, notes, and snippets.

@HackingGate
Last active May 6, 2019 08:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save HackingGate/661f9b7221a9b2e27cc6355d93cc8733 to your computer and use it in GitHub Desktop.
Save HackingGate/661f9b7221a9b2e27cc6355d93cc8733 to your computer and use it in GitHub Desktop.
Set himawari wallpaper shell script for macOS. (Linux & Windows not tested)
#!/bin/bash
PATH=$PATH:/usr/local/bin
echo `date`
echo "Checking himawari"
if ! type himawari > /dev/null; then
echo "Install himawari with:"
echo
echo "brew install imagemagick"
echo "brew install graphicsmagick"
echo "npm i himawari -g"
echo
else
mkdir -p /tmp/himawari
# Recommended values: 2160p(UHD/4K) use zoom 2; 4320p(8K) use zoom 3; 8640p(16K) use zoom 4;
echo "Downloading latest image"
himawari --zoom 2 --parallel --timeout 300000 --outfile /tmp/himawari/
fi
echo "Checking wallpaper"
if ! type wallpaper > /dev/null; then
echo "Install wallpaper with:"
echo
echo "brew install wallpaper"
echo
else
# If download succeeded, $image will be the latest image.
image=`find /tmp/himawari/himawari-*.jpg | tail -1`
current=`wallpaper get --screen main`
change=0
if [[ $current =~ ^/tmp/himawari/himawari-[0-9]*.jpg$ ]]; then
# If $current is himawari, update wallpaper without ask user.
change=1
else
# If $current is not himawari, ask user.
echo "Your current wallpaper is $current."
read -t 60 -r -p "Do you want to change? [Y/n] " input
case $input in
[yY][eE][sS]|[yY])
change=1
;;
[nN][oO]|[nN])
change=0
;;
*)
echo "Invalid input..."
exit 1
;;
esac
fi
# If download not succeeded, do not change wallpaper.
if [[ $change -eq 1 && $image != $current ]]; then
wallpaper set $image --screen main --scale fit
current=`wallpaper get --screen main`
echo "Wallpaper is changed to $current"
else
echo "Wallpaper is not changed"
fi
fi
@HackingGate
Copy link
Author

HackingGate commented Jan 30, 2019

Example:
Put set-himawari-wallpaper.sh file in ~/bin/
Run ~/bin/set-himawari-wallpaper.sh and answer yes
Save the following as ~/Library/LaunchAgents/com.hackinggate.set-himawari-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>Label</key>
  <string>com.hackinggate.set-himawari-wallpaper</string>
  <key>ProgramArguments</key>
  <array>
    <string>sh</string>
    <string>-c</string>
    <string>
      $HOME/bin/set-himawari-wallpaper.sh
    </string>
  </array>
  <key>StartInterval</key>
  <integer>600</integer>
  <key>RunAtLoad</key>
  <true/>
  <key>StandardErrorPath</key>
  <string>/tmp/com.hackinggate.set-himawari-wallpaper.stderr.log</string>
  <key>StandardOutPath</key>
  <string>/tmp/com.hackinggate.set-himawari-wallpaper.stdout.log</string>
</dict>
</plist>

Load as launchctl service

launchctl load ~/Library/LaunchAgents/com.hackinggate.set-himawari-wallpaper.plist

https://alvinalexander.com/mac-os-x/mac-osx-startup-crontab-launchd-jobs
https://stackoverflow.com/a/26586170/4063462

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment