invert screen in 10.5 Leopard

I previously wrote a script to invert the screen, but it was cumbersome in previous versions of MacOSX (although it worked perfectly fine). But in 10.5 there’s some new commands that allow for a much more elegant way to perform this task… so here’s the 10.5 way. :smiley: If you’re interested, you can see the old version here: http://bbs.applescript.net/viewtopic.php?pid=82131

-- this will only work on 10.5 Leopard or later
-- this assumes the first time you run the script you screen is normal i.e. not inverted colors
-- this is a "toggle" script... it will toggle between inverted screen colors and not-inverted screen colors on successive runs
-- it will work with any number of displays you have connected to your computer.
(* How it works: when your screens are inverted, the script will store the state of your current desktops for each display you have connected to your computer. It will set the desktop picture of each display to a white image so that when inverted your desktops will appear black. When the screen is returned to normal it will restore the stored desktop settings so your desktops appears like they were before you inverted them.*)

property displayProps : {}
property is_inverted : false
property invertPic : (path to desktop pictures folder as text) & "Solid Colors:Solid White.png"

if is_inverted then
	tell application "System Events"
		repeat with i from 1 to count of desktops
			tell desktop i
				set displayName to display name
				repeat with aProp in displayProps -- repeat through props to make sure you reset the proper display
					if theName of aProp is displayName then
						-- reset the desktop to its original values
						set picture rotation to theRotation of aProp
						set picture to (thePic of aProp) as file specification
						exit repeat
					end if
				end repeat
			end tell
		end repeat
		-- invert screens and toggle inverted state
		key code 28 using {command down, control down, option down}
		set is_inverted to false
	end tell
else -- screens are not inverted
	set displayProps to {}
	tell application "System Events"
		repeat with i from 1 to count of desktops
			tell desktop i
				-- get the display properties so you can reset them when you un-invert the screens
				set end of displayProps to {theName:display name, theRotation:picture rotation, thePic:picture as text}
				-- set the desktop to the invert picture and make sure the pic doesn't rotate
				set picture rotation to 0
				set picture to file invertPic
			end tell
		end repeat
		-- invert screens and toggle inverted state
		key code 28 using {command down, control down, option down}
		set is_inverted to true
	end tell
end if

Nice, and quick too. What do you use it for?

It is much faster now! There’s no more reading/writing to pref files and no more fiddling with multiple displays. The new commands really make it easy because each desktop is associated with a display so you can get that info easily.

I use this script to save my eyes. I stare at my screens for several hours a day and mostly I’m staring at some text on a page. As such I don’t really need to see proper colors most of the time. The black text on a white page gets to my eyes after awhile, especially at night when the screen seems brighter because there is no sunlight to counteract screen brightness. Dimming the screen doesn’t really work well. I find that inverting the colors so that the majority of the screen is dark and text is white allows me to still read everything easily and not have the bright screen shining in my eyes. It really cuts down on my eye strain.

I’m sure you might have known this already, or maybe you didn’t but you could press Alt + Command + 8 and get the same effect without the black background - although, I love your script, it’s a better adaption then the “three finger press” as I call it. I use the inversion for the same feature at night…

Nice thinking Regulus6633 !