Programmatically Show/Hide AppleScript Menu

Is there a method to programmatically set the AppleScript Editor Preferences to show/hide the AppleScript Menu in the Main Menu bar?

My search of MacScripter and the net was not successful in identifying such a program.

Thanks in advance for your feedback!

Ed

With AppleScript you can, see Kel1’s post using GUI scripting.

I misinterpreted your post, I thought you meant hiding certain things on your screen.

Thank you for your timely and interesting response!

I knew there had to be a way. I do want to stay within the bounds of OSX so hope that another solution might appear.

Thanks again,

Ed

Hi,

After you open Preferences in AppleScript Editor and go to the General tab toggle with ui scripting:

tell application "AppleScript Editor" to activate
tell application "System Events"
	tell process "AppleScript Editor"
		tell window "General"
			tell checkbox "Show Script menu in menu bar"
				click
			end tell
		end tell
	end tell
end tell

Edited: here’s the whole thing.

tell application "AppleScript Editor" to activate
tell application "System Events"
	keystroke "," using command down
	tell process "AppleScript Editor"
		tell window 1
			tell toolbar 1
				tell button "General"
					click
				end tell
			end tell
			tell checkbox "Show Script menu in menu bar"
				click
			end tell
		end tell
	end tell
	keystroke "w" using command down
end tell

It might not work internationally because of the names.

Edited: oops, forgot to close the preferences window.

gl,
kel

Here’s another way to show the Script Menu:

tell application "System Events"
	open file "Macintosh HD:System:Library:CoreServices:Menu Extras:Script Menu.menu"
end tell

Don’t know how to unshow it this way.

One more thing. AppleScript Editor is one of those apps where ‘activate’ doesn’t bring it to the front if it isn’t already running. To bring it to the front use launch or set the process to frontmost:

tell app "AppleScript Editor
launch
activate
end tell

gl,
kel

Here is an international version :

tell application "AppleScript Editor" to activate
tell application "System Events"
	keystroke "," using command down
	tell process "AppleScript Editor"
		tell window 1
			tell toolbar 1
				# name of buttons
				--> {"Général", "Modifications", "Formatage", "Historique", "Modules"}
				tell button 1 # "General"
					click
				end tell
			end tell
			# get title of every checkbox
			--> {"Afficher les scripts de l'ordinateur", "Afficher le menu des scripts dans la barre des menus", "Afficher les éléments hérités dans le visualiseur de dictionnaire"}
			set currentState to value of checkbox 2
			--> 1 if the box is checked
			--> 0 if the box is unchecked
			if currentState is 0 then
				tell checkbox 2 # "Show Script menu in menu bar"
					click
				end tell
			end if
		end tell
	end tell
	keystroke "w" using command down
end tell

Yvan KOENIG (VALLAURIS, France) mercredi 1 octobre 2014 19:58:01

Hi Yvan,

Thanks for the international version and more.

I was thinking that at the beginning, there should be a check to see if AppleScript Editor is already running. If it was not running then the script should quit the editor.

Edited: something like this:

set was_running to application "AppleScript Editor" is running
-- then at the end
if not was_running then tell "AppleScript Editor" to quit

Have a good day,
kel

Thanks a lot.
Just a detail, here it’s 21:30 so it’s the night :wink:

Yvan KOENIG (VALLAURIS, France) mercredi 1 octobre 2014 21:30:29

Hi Yvan,

I understand. Will be working on it.

Thanks again,
kel

Almost forgot about this thread. :slight_smile:

Darn, here’s something close, but the machine is telling me that the app does not allow assistive access. Anyway, here’s Yvan’s script with quitting the editor if it wasn’t running:

set was_running to application "AppleScript Editor" is running
tell application "AppleScript Editor"
	launch
	activate
end tell
tell application "System Events"
	keystroke "," using command down
	tell process "AppleScript Editor"
		tell window 1
			tell toolbar 1
				# name of buttons
				--> {"Général", "Modifications", "Formatage", "Historique", "Modules"}
				tell button 1 # "General"
					click
				end tell
			end tell
			# get title of every checkbox
			--> {"Afficher les scripts de l'ordinateur", "Afficher le menu des scripts dans la barre des menus", "Afficher les éléments hérités dans le visualiseur de dictionnaire"}
			set currentState to value of checkbox 2
			--> 1 if the box is checked
			--> 0 if the box is unchecked
			if currentState is 0 then
				tell checkbox 2 # "Show Script menu in menu bar"
					click
				end tell
			end if
		end tell
	end tell
	keystroke "w" using command down
end tell
if not was_running then tell application "AppleScript Editor" to quit

It might be a good exercise to debug this. :smiley:

gl,
kel

Hi Yvan,

For some reason it is not working now. I thought we were done, but it doesn’t seem so.

set was_running to application "AppleScript Editor" is running
tell application "AppleScript Editor"
	launch
	activate
end tell
tell application "System Events"
	keystroke "," using command down
	tell process "AppleScript Editor"
		tell window 1
			tell toolbar 1
				# name of buttons
				--> {"Général", "Modifications", "Formatage", "Historique", "Modules"}
				tell button 1 # "General"
					click
				end tell
			end tell
			# get title of every checkbox
			--> {"Afficher les scripts de l'ordinateur", "Afficher le menu des scripts dans la barre des menus", "Afficher les éléments hérités dans le visualiseur de dictionnaire"}
			set currentState to value of checkbox 2
			--> 1 if the box is checked
			--> 0 if the box is unchecked
			if currentState is 0 then
				tell checkbox 2 # "Show Script menu in menu bar"
					click
				end tell
			end if
		end tell
	end tell
	keystroke "w" using command down
end tell
if not was_running then tell application "AppleScript Editor" to quit

That’s ok. haoleserferdude is from Maui, so at least the local version will work. Just add the launching and quitting at the beginning and end. Until we have this sorted out.

gl,
kel

Darn, it is because of that assistive access thing. What to do? …

I have to buy eggs. :expressionless:

Will be thinking about this on the drive to the store.

gl,
kel

I don’t get it. Before you could just allow assistive access in System Preferences. I think it was in Accessibility. Now there are no apps showing. What happened to allow assistive access.

Nevermind. I found it in Security & Privacy just where it always was.

Yvan,

Helppp! When you get up. :slight_smile: Got it working with Assistive access, but it is not toggling. Need to try the local version again.

Ok, the local version works.

set was_running to application "AppleScript Editor" is running
tell application "AppleScript Editor" to activate
tell application "System Events"
	keystroke "," using command down
	tell process "AppleScript Editor"
		tell window 1
			tell toolbar 1
				tell button "General"
					click
				end tell
			end tell
			tell checkbox "Show Script menu in menu bar"
				click
			end tell
		end tell
	end tell
	keystroke "w" using command down
end tell
if not was_running then tell "AppleScript Editor" to quit

Need to debug the international version. Wake up! :smiley:

Later,
kel