0

I'm trying to get my dual monitors (connected to a MacBook Pro) to display ultrawide desktop backgrounds spanning them both. I've already made a small script that chops the images in half and puts them in corresponding folders (left and right), but every time I wake my computer from sleep it messes with the order and I get two non-matching pictures. I'd like to control this with a python script instead if possible. So far I've got a script that will change the primary display,

import random
import os

rand = random.randint(1, 25)
left = r'/Users/nickthomas/Documents/Wide_Background_Pics/Left/' + str(rand) + '.jpg'
right = r'/Users/nickthomas/Documents/Wide_Background_Pics/Right/' + str(rand) + '.jpg'

command = '''osascript -e 'tell application "Finder" to set desktop picture to POSIX file "''' + left + '"\''
os.system(command)

But I'm not sure how I can do the same with the second monitor. Can this be done with AppleScript or some other method?

Moddasir
  • 1,449
  • 13
  • 33

2 Answers2

0

You can use this code block inside your script.

from appscript import app, mactypes
app('Finder').desktop_picture.set(mactypes.File('/Path/Of/YourPicture.jpg'))
Moddasir
  • 1,449
  • 13
  • 33
  • [`appscript`](http://appscript.sourceforge.net/): `pip install appscript` – felipe Jan 31 '20 at 21:43
  • Thanks, but this still changes my primary display. Is there a way to modify this for the secondary display? – Nick Thomas Jan 31 '20 at 21:50
  • You can detect the monitor using then you can change the wallpaper or keep it as it is. https://developer.apple.com/documentation/appkit/nsscreen#//apple_ref/occ/clm/NSScreen/screens – Moddasir Jan 31 '20 at 21:58
0

Works on macOS Big Sur

For the Default monitor

osascript -e 'tell application "System Events" to set picture of current desktop to "<path-to-img>"'

For the second monitor

osascript -e 'tell application "System Events" to set picture of second desktop to "<path-to-img>"'
Helton Wernik
  • 185
  • 2
  • 3