Safari translation shortcuts

Apple released the novelty in the Safari application on MacOs, the translation. Displayed in the address bar in the right corner.
Will there be the possibility of creating a keyboard shortcut (or other) to activate the translation. The goal is not to use the cursor but the keyboard.

This is also available via the menubar menu (View => Translation => Translate to XXX )

Therefore you can assign the predefined action "Trigger Menubar Menu Item" to a keyboard shortcut and just enter "View;Translation;Translate to XXX" (adapt to the language of your system)

This was the first thing I set up once Big Sure was released. I love the built in translations and use it often.
Safari Translate.bttpreset (167.9 KB)

This AppleScript work's on German systems (Toggle):

tell application "System Events"
	tell application process "Safari"
		tell menu bar 1
			tell menu bar item "Darstellung"
				tell menu 1
					tell menu item "Übersetzung"
						tell menu 1
							if enabled of menu item 1 is true then
								tell menu item 1
									click
								end tell
							else
								if enabled of menu item 4 is true then
									tell menu item 4
										click
									end tell
								end if
							end if
						end tell
					end tell
				end tell
			end tell
		end tell
	end tell
end tell

You must replace "Darstellung" and "Übersetzung" with your menu entries. This might work on an English system (not tested):

tell application "System Events"
	tell application process "Safari"
		tell menu bar 1
			tell menu bar item "View"
				tell menu 1
					tell menu item "Translation"
						tell menu 1
							if enabled of menu item 1 is true then
								tell menu item 1
									click
								end tell
							else
								if enabled of menu item 4 is true then
									tell menu item 4
										click
									end tell
								end if
							end if
						end tell
					end tell
				end tell
			end tell
		end tell
	end tell
end tell

Why use AppleScript?
Isn't it easier to use the BTT Built-in 'Trigger Menubar Menu-Item?

The Script toggle the language (original -> default translation -> original …)

Thank you for your answers, you help me a lot.

But, it's more ergonomic/easy to use AppleScript or "Trigger Menubar Menu Item" for this shortcut, but with the option to go back to the original page.
That is to say to combine two "Trigger Menubar Menu Item" shortcuts:

  • "View; Translation; Translate to XXX",
  • "View; Translation; Back to the original page",
    in one shortcut?

You can't combine two "Trigger Menubar Menu Item" to toggle "Translate to XXX" <-> "Back to the original page" in one shortcut, because you must check the states.

If you want to toggle, then you must use an (the) Apple Script. If you want only "Translate to XXX", you can use the "Trigger Menubar Menu Item" or you make two shortcuts. One for "Translate to XXX" and one for "Back to the original page".

In general it should work like this:

View;Translation;Translate to German||View Original, (the || operator will trigger the first if it is available, otherwise the second item. Unfortunately there was a bug in the current BTT which breaks this behavior. I have fixed it and will upload a new version later today.

1 Like

@Andreas_Hegenberg: Super! That saves a lot!