0

I have written python script to change desktop wallpaper.

After I change my wallpaper using the below code:

app('Finder').desktop_picture.set(mactypes.File(imageAddress))

I have added

os.system("killall Dock")

The wallpaper successfully changes, but all the active but minimized windows maximize. My question is How do I refresh my Dock without changing the state of minimized/maximized windows?

I have also tried the below methods :

tell application "Finder" to set desktop picture to POSIX file "/Library/Desktop Pictures/Milky Way.jpg"

osascript -e 'tell application "Finder" to set desktop picture to POSIX file "/Library/Desktop Pictures/Milky Way.jpg"'

My python code is below:

#from appscript import app, mactypes
import subprocess
import os

def change_desktop_wallpaper(imageAddress):
    #app('Finder').desktop_picture.set(mactypes.File(imageAddress))
    #os.system("Killall Dock")
    Script = ''' osascript -e 'tell application "Finder" to set desktop picture to POSIX file "/Users/princechawla/timepass/quotesWall/myquotewallpaper.jpg" ' '''
    os.system(Script)
    #os.system(''' osascript -e tell application "Finder" to set desktop picture to POSIX file "/Users/princechawla/timepass/quotesWall/myquotewallpaper.jpg" ''')
    #subprocess.Popen(Script , shell=True)
    #os.system("killall Dock")

None of the work without using killall Dock

I have asked the same question here :

killall Dock - all active windows maximize and appear on Desktop

This might look like duplicate of :

programmatically change the background of mac OSX

but none of the answers in any of the questions work.

thenakulchawla
  • 5,024
  • 7
  • 30
  • 42

1 Answers1

0

This works for me on the latest version of OSX Sierra

tell application "System Events" to set picture of current desktop to POSIX file "/Library/Desktop Pictures/Milky Way.jpg"
wch1zpink
  • 3,026
  • 1
  • 8
  • 19