Instance Method


Sets the desktop image for the given screen to the image at the specified URL.


func setDesktopImageURL(_ url: URL, for screen: NSScreen, options: [NSWorkspace.DesktopImageOptionKey : Any] = [:]) throws



A file URL to the image. The URL must not be nil.


The screen to set the desktop image on.


The options dictionary may contain any of the Desktop Image Dictionary Keys keys, which control how the image is scaled on the screen.


A error that is returned by-reference if setting the image fails.

Return Value

true if the image was set as the desktop, otherwise false. If false is returned, the error parameter provides additional information.


You should not present a user interface for picking the options. Instead, choose appropriate defaults and allow the user to adjust them in the System Preference Pane.

You must call this method from your app’s main thread.

See Also

Managing the Desktop Image

func desktopImageURL(for: NSScreen) -> URL?

Returns the URL for the desktop image for the given screen.

struct NSWorkspace.DesktopImageOptionKey

The following keys may be specified or returned in the options dictionary for setDesktopImageURL(_:for:options:).