Below is my current code but it doesn’t seem to work at all…
If possible could anyone help me fix it, pretty please!!!
use AppleScript version "2.8"
use scripting additions
-- Open the Menu Bar pane
do shell script "open 'x-apple.systempreferences:com.apple.ControlCenter-Settings.extension?MenuBar'"
tell application "System Events"
tell application process "System Settings"
set frontmost to true
-- wait for the window & scroll area to exist
repeat until (exists window 1)
delay 0.1
end repeat
set w to window 1
repeat until (exists scroll area 1 of w)
delay 0.1
end repeat
set sa to scroll area 1 of w
-- find the (unnamed) popup by its value, anywhere inside the scroll area
set p to missing value
repeat 200 times
try
set p to first pop up button of (entire contents of sa) ¬
whose value is in {"Never", "In Full Screen Only", "On Desktop Only", "Always"}
exit repeat
on error
delay 0.1
end try
end repeat
if p is missing value then error "Could not locate the pop-up button. Check Accessibility/Automation permissions."
-- choose the other setting (Never ↔ In Full Screen Only)
set curVal to value of p
if curVal is "Never" then
set targetItem to "In Full Screen Only"
else
set targetItem to "Never"
end if
try
perform action "AXScrollToVisible" of p
end try
perform action "AXPress" of p
delay 0.2
click menu item targetItem of menu 1 of p
end tell
end tell
@cikip82178
Welcome, cikip!
I’m not very good at UI scripting, so I’ll leave the System Events part to others.
As for everything else:
The menu bar settings are configured as a combination of two values.
So you can get the current settings from NSUserDefaults.
Of course, you can also use: defaults read -g AppleMenuBarVisibleInFullscreen defaults read -g _HIHideMenuBar
to read (and even change) the current values.
I think the key point is just being able to get the current settings…
Hope this helps!
Option
AppleMenuBarVisibleInFullscreen
_HIHideMenuBar
bool
Always
0
1
false:true
Never
1
0
true:false
On Desktop Only
1
1
true:true
In Full Screen Only
0
0
false:false
#!/usr/bin/env osascript
use AppleScript version "2.8"
use framework "Foundation"
use scripting additions
property refMe : a reference to current application
####################
#setting record
set recordSettingRev to {|01|:"Always", |10|:"Never", |00|:"In Full Screen Only", |11|:"On Desktop Only"} as record
#MakeDict
set ocidSettingRevDict to refMe's NSMutableDictionary's alloc()'s init()
ocidSettingRevDict's setDictionary:(recordSettingRev)
log ocidSettingRevDict as record
####################
#NSUserDefaults
set appUserDefaults to refMe's NSUserDefaults's standardUserDefaults()
set ocidRootDict to appUserDefaults's persistentDomainForName:(".GlobalPreferences")
####################
#value AppleMenuBarVisibleInFullscreen integer
set boolInFull to (ocidRootDict's objectForKey:("AppleMenuBarVisibleInFullscreen"))'s integerValue()
####################
#value _HIHideMenuBar integer
set boolHide to (ocidRootDict's objectForKey:("_HIHideMenuBar"))'s integerValue()
#Value
set itemKey to ("" & boolInFull & boolHide & "") as text
log (ocidSettingRevDict's objectForKey:(itemKey)) as text
return (ocidSettingRevDict's objectForKey:(itemKey)) as text