NSApp.appearance

According to: https://developer.apple.com/documentation/appkit/nsappearancecustomization/choosing_a_specific_appearance_for_your_app

We can specify if our apps are Light/Dark mode via the below (amongst other methods).

Can someone help with the syntax for the above in an AppleScriptObjC app?

Here is a script to detect current Appearance name and return true/false.
This script works fine with Script Editor or Script Debugger. But can not detect with AppleScript application project on Xcode.


use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "Foundation"
use scripting additions

set apRes to retLightOrDark() of me


on retLightOrDark()
	set pInfo to (current application's NSProcessInfo's processInfo()'s operatingSystemVersion()) as record
	set aVer to (minorVersion of pInfo) as integer
	
	if aVer = 13 then
		try
			set sRes to (do shell script "defaults read -g AppleInterfaceStyle")
			return (sRes = "Dark") as boolean
		on error
			return false
		end try
	else if aVer > 13 then
		--macOS 10.14 or later
		set curAppearance to ((current application's NSAppearance)'s currentAppearance()'s |name|()) as string
		if curAppearance = "NSAppearanceNameDarkAqua" then
			return true
		else
			return false
		end if
	else
		return false
	end if
end retLightOrDark


Model: MacBook Pro 2012
AppleScript: 2.7
Browser: Safari 13.0.1
Operating System: macOS 10.14

This works with AppleScript application on Xcode.


use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "Foundation"
use scripting additions

set apRes to retLightOrDark() of me
--> true (Dark), false (Light)


on retLightOrDark()
	try
		set sRes to (do shell script "defaults read -g AppleInterfaceStyle")
		return (sRes = "Dark") as boolean
	on error
		return false
	end try
end retLightOrDark