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 on which to set the desktop image.


The options dictionary may contain any of the keys in NSWorkspace.DesktopImageOptionKey, which control how the image is scaled on the screen.


An error object indicating the success or failure of the action. Specify a variable to store the error object. The method sets this variable to nil on success, or to an NSError object if a problem occurred.

Return Value

true if the method set the desktop image; otherwise false. If the method returns false, the error parameter provides additional information.


Instead of presenting a user interface for picking the options, 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

Keys that indicate how to display a new desktop image.