killall Dock - all active windows maximize and appear on Desktop 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 in the maximize.
My question is
 How do I refresh my Dock without changing the state of minimized/maximized windows?
I know of no way to keep minimized windows from being restored when executing a killall Dock command, by any method.

The long workaround is to enumerate all application processes with visible windows and make a list of all minimized windows before executing killall Dock and then use the list to re-minimize afterwards. I seriously don't recommend doing that, but it's doable if you want to spend the time coding it.

That said, why not just use a method that doesn't require using killall Dock and immediately changes the wallpaper?

Here are two examples using AppleScript:

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


Or:

tell application "Finder" to set desktop picture to alias "Macintosh HD:Library:Desktop Pictures:Sierra.jpg"


From the command line, e.g. in Terminal or shell based script:

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


Any of these immediately changes the wallpaper without further need to do anything.