#!/bin/bash

set_wallpaper() {
  osascript -e "tell application \"System Events\" to tell every desktop to set picture to \"${1}\" as POSIX file"
}

# to change the wallpaper on all spaces
for i in $(seq 1 16); do
  osascript -e "tell application \"System Events\" to key code 124 using control down"
  sleep 1
  set_wallpaper "$1"
done

/usr/bin/osascript -e '
tell application "System Events"
    tell every desktop
        set picture to "path_to_wallpaper.jpg"
    end tell
end tell
'

osascript -e 'tell application "System Events" to tell every desktop to set picture to "path_to_wallpaper.jpg"'

osascript -e 'tell application "Finder" set desktop picture to POSIX file "/Library/Desktop Pictures/Solid Colors/Solid Gray Dark.png" end tell'
