Allocate a shortcut to an existing menu bar command

Hello,
how can I allocate a shortcut to an existing menu bar command ”Sprachausgabe” (German version of “Voice output”?).

The following is an AppleScript that is similar to what you could produce.

The AppleScript is in TEXT form (a .txt file) instead of an APPLESCRIPT form (.scpt file), because the Brave Community’s Discourse software limits the types of files that may be uploaded to the forum.

AppleScripts are created by using the “Script Editor.app” located on your Mac, in the Utilities folder:

/Applications/Utilities/Script Editor.app

In order to run the following AppleScript, you would

  1. Copy all of the text of the script.
  2. Paste that into a new Script Editor.app window.
  3. Save that AppleScript.
  4. With Brave Browser running, select some word in the body of the browser window.
  5. Run the AppleScript.
  6. The word that you selected in the browser window, will be copied to the Clipboard.

The AppleScript begins with a “–” line and ends with the same type of line. The “–” two hyphens, are a way of commenting out a line.

Lines between a set of:

(* and
*)
are also comments.



-- START of AppleScript
--
(*

Gives you an idea, of how to use the MacOS "Script Editor.app" (in the Utilities folder), for creating an AppleScript.

The following AppleScript, is very similar to what will work for you - selecting a Brave Browser menu item.

*)
--
--
tell application "Brave Browser"
activate
tell application "System Events"
tell menu item "Copy" of menu "Edit" of menu bar item "Edit" of menu bar 1 of application process "Brave Browser"
-- UI elements
click
end tell
end tell
end tell
--
--
(*

Some Guidance and Reference materials

"AppleScript - The Language of Automation"
https://macosxautomation.com/applescript/firsttutorial/index.html

"AppleScript Lexical Conventions"
https://developer.apple.com/library/archive/documentation/AppleScript/Conceptual/AppleScriptLangGuide/conceptual/ASLR_lexical_conventions.html

"MacScripter.net"
https://www.macscripter.net/

*)
--
-- END of AppleScript

Thank you very much “289wk” … steps 1-3 done but I am struggling with step
4. With Brave Browser running, select some word in the body of the browser window.
… what means “select some word” + were is “the body of the browser window.”
Maybe stupid questions, but my tech-skills are limited ;-(.
Thank you and nice greetings, Thomas

Some word (‘STRUGGLING’), selected:

What the basic core of the AppleScript looks like:

Oh … sorry but now I am completely confused with your explanations.
One more try …

I do not know what:
“4. With Brave Browser running, select some word in the body of the browser window.”
means.

I already produced and saved the AppleScript … by following your steps 1-3.

Based on “do not know …” 4. I am not able to:
5. Run the AppleScript.

Windows dissables scrips by default. Here you can learn how to write a script in Powershell and how to activate scriping in Windows.

Create a Powershell Script File

:slight_smile: … I am working with MacOS not Windows.

@Thomas28 ,

I previously wrote: “select some word in the body of the browser window”

You replied: "What means “select some word” and “Where is ‘the body of the browser window?’”

Me, using Brave Browser, went to a search engine’s search field and entered 1 keyword:

struggling

The results of that search, was a webpage, and in the body of that webpage, was the Cambridge Dictionary information - including the word “struggling” that I selected; and I posted a screenshot.

In addition, so that you could verify that you correctly saved the basic core of the AppleScript, I posted a screenshot of how those lines of the AppleScript, appear on my Mac computer.

My aim, is to get you through a “Crash Course on AppleScript” . . . so you can learn/see how an AppleScript works.

And so, you can manage to create your own AppleScript that satisfies your objective of having a tool - what you call a “shortcut” for selecting something in a menu bar’s menu.

In order for you to create the AppleScript, you would:

  1. Duplicate the existing AppleScript that I gave to you

  2. Name that duplicate AppleScript, something like “Select_Menu_Bar_Command.scpt”

  3. Edit your AppleScript, such that, when run, it selects the particular menu item “Sprachausgabe” of interest to you.

Thanks a lot 289wk for your patience and efforts.
After a few more trys I realized, that the solution with the AppleScript means, I have to run the script evey time I would like to start “Sprachausgabe” (Voice Output) in Brave.
My goal was to “allocate a shortcut” (key combination … e.g. shift+command+S) to the existing menu of Brave - to have it permanently available in Brave.
I now realized, that it makes no sense (no time saving) to always run the AppleScript before using “Sprachausgabe” - easier and faster is to just select “Bearbeiten/Sprachausgabe” with the mouse.
I probably did not make this claear anough in my request - sorry for that and thank you again for your time and patience.

May interest:
MacOS Keyboard Shortcuts:

https://support.apple.com/en-us/102650


Simple AppleScript for you to run:

set x to "This is a dialog example"
display dialog x
tell me to set currDate to ((current date) as string)
display dialog currDate

Good luck.

Excellent 289wk - thank you so much - it now works :-).
Simply done with your suggested “MacOS Keyboard Shortcuts:”
Nice greetings from Germany.

1 Like