How to set desktop background color with applescript

Is there a way to change the desktop background color with Applescript? (or other CLI tool)

NOT the desktop wallpaper image, the color behind the image.


I can see it there in System preferences on the Wallpaper settings (I've chosen purple). But can't find a way to change it from the CLI.



The "closest" feels like:

tell application "System Events"
  tell desktops
    set color to {1, 1, 1}
  end tell
end tell

Can’t set color to {1, 1, 1}. Access not allowed.

I think I just need to know what the property should be called and then it will be easy...

I've tried things like "desktop color" and "background color" and various similar combos.

Posted on Jun 17, 2025 4:09 AM

Reply
Question marked as Top-ranking reply

Posted on Jun 17, 2025 9:16 AM

I believe you can have either a wallpaper image, or a solid wall paper background, but not both where a smaller image is centered on the display with a color fill behind it.


The following AppleScript does the latter. It prompts you for the screen color from the AppleScript color chooser, the image that you want centered on the Desktop, and then applies that image to the first Desktop with a calibrated color background that you selected.


(*
Center_Img_ColorBG.applescript

Center an image on the Desktop with the selected calibrated color background
Tested: macOS Sequoia v15.5
VikingOSX, 2025-06-17, Apple Support Community, No warranties expressed or implied.
*)

use framework "AppKit"
use scripting additions

property ca : current application

-- see NSImageScaling enumerators in AppKit. Here we want to center an image
set NSImageScaleAxesIndependently to ca's NSNumber's numberWithUnsignedInteger:2

-- prompt the user for the desired background color
set {R, G, B} to (choose color)

-- set the calibration decimals for R, G, B
set {rn, gn, bn} to my calibratedColors(R, G, B)

-- the background color fill to place behind the centered image
set fillColor to ca's NSColor's colorWithCalibratedRed:rn ¬
	green:gn ¬
	blue:bn ¬
	alpha:1.0

set dictObjects to {fillColor, NSImageScaleAxesIndependently}
set dictKeys to {ca's NSWorkspaceDesktopImageFillColorKey, ca's NSWorkspaceDesktopImageScalingKey}
set dtDict to ca's NSDictionary's alloc's initWithObjects:dictObjects forKeys:dictKeys

try
	-- select the image to center on the principal desktop
	set thisImg to ca's NSURL's fileURLWithPath:(POSIX path of (choose file of type {"public.image"}) as text)
on error
	return
end try

set theScreens to ca's NSScreen's screens()
(ca's NSWorkspace's sharedWorkspace)'s setDesktopImageURL:thisImg ¬
	forScreen:(theScreens's objectAtIndex:0) ¬
	options:dtDict ¬
	|error|:(reference)
return

on calibratedColors(rx, ry, rz)
	set rc to (do shell script "echo \"scale=3;" & rx & "/65535\" | bc -l")
	set gc to (do shell script "echo \"scale=3;" & ry & "/65535\" | bc -l")
	set bc to (do shell script "echo \"scale=3;" & rz & "/65535\" | bc -l")
	return {rc, gc, bc} as list
end calibratedColors


An an example, I selected your chosen screen color, a dogcow moof image, and the following was captured from the center of my 32-in screen:


1 reply
Question marked as Top-ranking reply

Jun 17, 2025 9:16 AM in response to maxallan1

I believe you can have either a wallpaper image, or a solid wall paper background, but not both where a smaller image is centered on the display with a color fill behind it.


The following AppleScript does the latter. It prompts you for the screen color from the AppleScript color chooser, the image that you want centered on the Desktop, and then applies that image to the first Desktop with a calibrated color background that you selected.


(*
Center_Img_ColorBG.applescript

Center an image on the Desktop with the selected calibrated color background
Tested: macOS Sequoia v15.5
VikingOSX, 2025-06-17, Apple Support Community, No warranties expressed or implied.
*)

use framework "AppKit"
use scripting additions

property ca : current application

-- see NSImageScaling enumerators in AppKit. Here we want to center an image
set NSImageScaleAxesIndependently to ca's NSNumber's numberWithUnsignedInteger:2

-- prompt the user for the desired background color
set {R, G, B} to (choose color)

-- set the calibration decimals for R, G, B
set {rn, gn, bn} to my calibratedColors(R, G, B)

-- the background color fill to place behind the centered image
set fillColor to ca's NSColor's colorWithCalibratedRed:rn ¬
	green:gn ¬
	blue:bn ¬
	alpha:1.0

set dictObjects to {fillColor, NSImageScaleAxesIndependently}
set dictKeys to {ca's NSWorkspaceDesktopImageFillColorKey, ca's NSWorkspaceDesktopImageScalingKey}
set dtDict to ca's NSDictionary's alloc's initWithObjects:dictObjects forKeys:dictKeys

try
	-- select the image to center on the principal desktop
	set thisImg to ca's NSURL's fileURLWithPath:(POSIX path of (choose file of type {"public.image"}) as text)
on error
	return
end try

set theScreens to ca's NSScreen's screens()
(ca's NSWorkspace's sharedWorkspace)'s setDesktopImageURL:thisImg ¬
	forScreen:(theScreens's objectAtIndex:0) ¬
	options:dtDict ¬
	|error|:(reference)
return

on calibratedColors(rx, ry, rz)
	set rc to (do shell script "echo \"scale=3;" & rx & "/65535\" | bc -l")
	set gc to (do shell script "echo \"scale=3;" & ry & "/65535\" | bc -l")
	set bc to (do shell script "echo \"scale=3;" & rz & "/65535\" | bc -l")
	return {rc, gc, bc} as list
end calibratedColors


An an example, I selected your chosen screen color, a dogcow moof image, and the following was captured from the center of my 32-in screen:


This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

How to set desktop background color with applescript

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.