Skip to content

Instantly share code, notes, and snippets.

@mironovd
Created December 1, 2014 10:11
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 mironovd/6b06f0c9604b00dde9ff to your computer and use it in GitHub Desktop.
Save mironovd/6b06f0c9604b00dde9ff to your computer and use it in GitHub Desktop.
Apple script to set all background on all displays and all spaces
set displaylist to {}
tell application "System Events"
set theDesktops to a reference to every desktop
repeat with n from 1 to count of theDesktops
tell item n of theDesktops
set dn to display name
set p1 to picture
end tell
set k to {dn:p1}
set end of displaylist to {d:dn, p:p1}
end repeat
end tell
set numSpaces to 16
tell application "System Events" to key code 122 using {command down, control down, option down, shift down}
repeat (numSpaces + 1) times
tell application "System Events"
set theDesktops to a reference to every desktop
repeat with n from 1 to count of theDesktops
tell item n of theDesktops
set dn to display name
repeat with k from 1 to count of displaylist
set pp to item k of displaylist
set ddn to d of pp
set ppn to p of pp
if ddn = dn then
set picture to ppn
end if
end repeat
end tell
end repeat
end tell
delay 1
tell application "System Events" to key code 124 using {command down, control down, option down, shift down}
end repeat
tell application "System Events" to key code 122 using {command down, control down, option down, shift down}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment