If then syntax issues

I am trying to make a script to toggle hiding/showing the dock and menu bar. I cannot figure out the syntax to detect if they are currently hidden or not

if the dock preferences of autohide is true then

if the dock preferences of autohide equal true then

I Based the above examples on the code I used to actually set the preferences but no luck


tell application "System Events" to set the autohide of the dock preferences to true
tell application "System Events" to set the autohide menu bar of the dock preferences to true

my google-fu is insufficient and I can’t even get google to understand what I’m searching for I’m terrible at learning from tutorials and typically inspect other’s code to learn does anyone have suggestions on applescript repositories i could check out?

The following will do what you want:

tell application "System Events"
	if (autohide of dock preferences is true) then
		set autohide of dock preferences to false
	else
		set autohide of dock preferences to true
	end if
end tell

This is a minor point, but boolean properties don’t have to be explicitly compared against true/false, as their existence is the truth.

 tell application "System Events" to (autohide of dock preferences) -->true/false

–or


tell application "System Events"
	tell dock preferences to if its autohide then
		set autohide to false
	else
		set autohide to true
	end if
end tell

Also, here is the other part you were struggling with.

tell application "System Events"
	if autohide menu bar of dock preferences then
		set autohide menu bar of dock preferences to false
	else
		set autohide menu bar of dock preferences to true
	end if
end tell

I tested wch1zpink’s script but it refused to compile. I looked at the System Events dictionary and didn’t see an autohide setting for the menu bar. Did I miss something?

It works for me on Big Sur

It looks like Big Sur has introduced new functionality implemented with the autohide menu bar property. At least in Catalina it is absent.

It only surprises me that all experienced users (@peavine, @Marc Anthony and @wch1zpink) suggest bad programming practice to a beginner.


tell application "System Events" to tell dock preferences to set autohide menu bar to not (autohide menu bar)

Instead of criticizing other people’s solutions and trying to portray yourself as superior to everyone else, I would suggest going back and re-read the Topic of the OP’s question. It specifically says [center]

[/center]

It seems to me that (@peavine, @Marc Anthony and @wch1zpink) are the only ones who offered complete solutions which address the If then syntax issues and the toggle hiding/showing the dock and menu bar

My Suggestion: lighten up dude… We’re all here to help.

wch1zpink. Thanks for explaining that and for the screenshot. I checked both the Script Editor and Script Debugger dictionaries and autohide menu bar isn’t anywhere to be found under Catalina. I appreciate the correction.

I agree that KniazidisR’s comment is both incorrect and rude. Sometimes I see otherwise cordial forum members say stuff like that and I have to wonder if it’s because English isn’t their native language. I hope that’s the case anyways.

After @peavine’s comment, I searched for the rude place and found it. I apologize for the disturbance caused, and I am correcting the error. Somehow, instead of the word “experienced”, Google Translate translated “advanced”.