Seamlessly change all desktop spaces' wallpaper on Mac without killall Dock - macos

I would like to change the wallpaper on ALL desktops including spaces on Mac but without needing to call killall Dock each minute. (Dock restarting forces wallpaper refresh).
I have an AppleScript that changes the desktop wallpaper instantly:
tell application "System Events" to tell every desktop to set picture to wallpaperPath
but that only changes the wallpaper on the active space (meaning that if the main desktop is not active, its background will not change).
I found this question How to loop through all Mac desktop spaces which suggests updating wallpaper path values in the SQLite database located at ~/Library/Application Support/Dock/desktoppicture.db. This changes the wallpaper at every space which is great but it requires restart of the dock using killall Dock which is undesirable as it disrupts the workflow.
My question is - is there some way to combine these two approaches? Seamlessly change wallpapers on every desktop space?
Any suggestions would be appreciated. I have no preferred language, it can be in C, Swift, Python, Bash, AppleScript etc.

I figured it out.
I am looping through all available screens and setting the wallpaper using setDesktopImageURL:forScreen:options:error::
for screen in NSScreen.screens {
try! NSWorkspace.shared.setDesktopImageURL(url, for: screen, options: [:])
}
This changes the wallpapers seamlessly, without the need for killall Dock on all the screens but only if the desktop is the active space.
To make sure the wallpaper is changed when I am on another space (usually a fullscreen app), I added an observer for NSWorkspace.activeSpaceDidChangeNotification on the NSWorkspace.shared.notificationCenter which sets the desktop images again (using the code above). So whenever I go back to the desktop, this notification is invoked and the wallpaper is seamlessly updated.
I even went one step further and added the same observer also for the NSWorkspace.didWakeNotification which updates the wallpaper as soon as the device wakes up which is cool!

Related

How to figure out which application window is on the top?

I am a noob when it comes to Desktop GUIs. Is there a way for me to programmitically figure out which application window is the top most in terms of display environment?
So, basically, I can have a process running in the background, that might then change the behavior of the top-most (or say the selected) window. My go to operating system would be MacOS (then Linux family). Also, for instance, there is an app called spectacle app, which listens to key bindings to snap resize and move active windows on MacOS.

Is it possible to programmatically detect a click on the mac desktop?

I want to whip something up that would run a small script every time i clicked on the Desktop. Any hints on how to make this happen?
For those interested, the script would toggle the display of desktop icons.
I assume you mean on the desktop background, not any icon. You could create a transparent overlay window, use [window setIgnoresMouseEvents:NO] to make it receive clicks, and set its window level to something between the desktop and the icons (kCGDesktopWindowLevel and kCGDesktopIconWindowLevel).
You would presumably want to create one of those per screen and monitor for changes in the screen configuration to add, remove, or resize them as appropriate. Either observe the NSApplicationDidChangeScreenParametersNotification or implement the -applicationDidChangeScreenParameters: application delegate method (which amounts to the same thing).

How can I make any icon on the Mac dock bounce?

I would like to be able to make an app's icon on the dock, for any application, bounce with a keyboard command. Is there any way I can do this?
It would need to work on all application icons, so for example which ever application is currently in use, the keyboard command would make that icon bounce like it does when the application is opening - although preferably it could bounce just once.
I presume some sort of script?
Thanks

How can I tell if the taskbar is using small icons

I'm looking for a way to detect if the user is using small icons :
I couldn't find anything in GetSystemMetrics \ SystemParametersInfo.
I tried to use the "Running applications" window's size :
it works fine when the taskbar's orientation is bottom\top, but when it's left\right this window takes the entire taskbar width.
Any ideas?
Deskbands are not quite dead on Windows, but they are on life-support. First make sure if you don't want to take advantage of thumbnail toolbars, ITaskbarList3::ThumbBarXxx() functions.
I'm not aware of an api to read back the button size setting. There's a backdoor you can use, these configuration settings are always saved to the registry. Run SysInternals' ProcMon utility and change the setting. On my machine (Windows 8), out popped this registry key:
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced\TaskbarSmallIcons
That almost surely works, I can't guarantee anything beyond Windows 8 of course.

How to move a window to a certain desktop with AppleScript?

I have an application/window on Desktop 1 (OS X Lion) and I'd like to move it to Desktop 3. Any insights on how to do this? Not as big a deal, but if possible I'd like to ensure there are 3 and only 3 Desktops available.
This answer should offer clues on how to do place applications, specifically...
tell application "System Events"
set x to application bindings of spaces preferences of expose preferences
set x to {|com.apple.textedit|:4} & x -- Have TextEdit appear in space 4
set application bindings of spaces preferences of expose preferences to x
end tell
I would imagine moving a window is not too different.
I realize this question is old, but in case anyone still needs this functionality, I thought I'd share my solution.
Because there aren't any real scripting exposures in Mission Control, you'll need to manipulate the cursor and thus will need access to the Objective-C bridge. This requires using the JXA variant of AppleScript, but still allows things to run natively without any plugins.
If you're still interested I've shared the solution on my GitHub repository, stephan-hates-osascript.
Moving a window works while switching to different desktops with a keyboard shortcut.
With the mouse, click and hold the title bar as if you are moving the window around your desktop, then press ctrl+3. Ctrl+3 has to be mapped to move to desktop 3 in the keyboard shortcuts interface. Ctrl+Right twice also works. Then release the mouse button.

Resources