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 in the maximize. My question is How do I refresh my Dock without changing the state of minimized/maximized windows?

1 Answer 1

1

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.

2
  • I have to still use killall Dock for the changes to take place. Even when I run the above from my shell, unless I run killall Dock, the latest changes don't take place. Jun 19, 2017 at 0:18
  • @nakulchawla09, On my system running 10.12.5, the change in wallpaper is immediate and no need to use killall Dock. Jun 19, 2017 at 9:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .