How to select specific language in the upper right menu on a Mac with applescript? Big Sur - menu

How can I select a specific (English in my case) language in the upper right menu on a Mac using an apple script.
My code is really slow. It take about 5 sec for it.
Do you have fast and smart ideas?)
tell application "System Events" to ¬
tell application process "TextInputMenuAgent" to ¬
tell menu bar item 1 of menu bar 2
click
click menu item 1 of menu 1
end tell

You might be able to use the standard keyboard shortcut used for selecting keyboard layouts.
The defaults are Ctrl-Space (previous layout) and Alt-Ctrl-Space (next layout), although it wraps around, so if you have only two languages, either will simply toggle the layout.
This can be scripted thusly:
tell application "System Events"
key code 49 using control down
end tell
Please be aware that this shortcut may be disabled (or changed) by a given user in the System Preferences->Keyboard->Shortcuts->Input Source although If you are the only user, this wont be a problem.
Some more ideas may be found at Change OSX keyboard layout("input source") programmatically via terminal or AppleScript?

The example AppleScript code, shown below, was tested in Script Editor and as an Automator Service/Quick Action under macOS Catalina and macOS Big Sur with Language & Region settings in System Preferences set to English (US) — Primary and worked for me without issue1.
1 Assumes necessary and appropriate settings in System Preferences > Security & Privacy > Privacy have been set/addressed as needed.
Example AppleScript code:
ignoring application responses
tell application "System Events" to ¬
click menu bar item 1 of ¬
menu bar 2 of ¬
application process "TextInputMenuAgent"
end ignoring
delay 0.1
do shell script "killall 'System Events'"
delay 0.2
tell application "System Events"
launch
click menu item 1 of ¬
menu 1 of ¬
menu bar item 1 of ¬
menu bar 2 of ¬
application process "TextInputMenuAgent"
end tell
Notes:
In the second tell application "System Events" block:
Change:
click menu item 1 of ¬
To:
The actual name of the menu item, e.g click menu item "U.S." of ¬ or whatever the actual name is.
You can also change the number e.g. 1 to whatever number is appropriate.
As tested, this works for me without issue and, sans the built-in three tenths of a second combined delay, was instantaneous.
If the example AppleScript code shown above does not work for you, then use the Using: cliclick method shown in my answer AppleScript - Can't get rid of delay after click
Or for a more robust solution also using cliclick, a third-party command line utility, the following example AppleScript code can be used for more than the immediate menu item you are trying to click.
Example AppleScript code:
-- # This script works on menu bar items in menu bar 2.
-- # Set the name of the application process and the
-- # name of the target menu item. It will use cliclick
-- # a third-party command line utility to perform the
-- # clicks as a workaround to the 5 second delay bug.
-- #
-- # Note that this requires the target menu item to have
-- # a name that System Events can retrieve properties for.
-- # It is from these properties it position and size is
-- # ascertained in order to calculate where to click it.
-- # User set properties.
property appProcessName : "TextInputMenuAgent"
property menuItemName : "U.S."
property cliclick : "/usr/local/bin/cliclick"
-- # The code below is tokenized and
-- # should not need to modified.
property xPos : missing value
property yPos : missing value
tell application "System Events" to ¬
set thePositionSizeList to ¬
the {position, size} of ¬
menu bar item 1 of ¬
menu bar 2 of ¬
application process ¬
appProcessName
my setXposYposFrom(thePositionSizeList)
my clickAtXposYpos()
tell application "System Events"
set theTargetMenuItemProperties to ¬
properties of ¬
first menu item of ¬
menu 1 of ¬
menu bar item 1 of ¬
menu bar 2 of ¬
application process ¬
appProcessName whose ¬
name is menuItemName
set thePositionSizeList to ¬
the {position, size} of ¬
theTargetMenuItemProperties
end tell
my setXposYposFrom(thePositionSizeList)
my clickAtXposYpos()
-- ## Handlers ##
to setXposYposFrom(thisList)
set xPos to ¬
(item 1 of item 1 of thisList) + ¬
(item 1 of item 2 of thisList) / 2 ¬
as integer
set yPos to ¬
(item 2 of item 1 of thisList) + ¬
(item 2 of item 2 of thisList) / 2 ¬
as integer
end setXposYposFrom
to clickAtXposYpos()
set shellCMD to {¬
cliclick, " -r c:", ¬
xPos, ",", yPos} as string
do shell script shellCMD
end clickAtXposYpos
Note: The example AppleScript code is just that and sans any included error handling does not contain any additional error handling as may be appropriate. The onus is upon the user to add any error handling as may be appropriate, needed or wanted. Have a look at the try statement and error statement in the AppleScript Language Guide. See also, Working with Errors. Additionally, the use of the delay command may be necessary between events where appropriate, e.g. delay 0.5, with the value of the delay set appropriately.

You don't say what OS version you're on but this works on Sierra; no idea whether it works on other versions. Per comments, apparently this should work up to Movaje, but not in Catalina or newer.
You may have to tweak this for your own setup as the status menu items will likely be in a different order than mine. Try setting it to item 1 first and then work your way up to the correct menu.
Of course, it assumes that you have enabled 'Show input menu in menu bar' in System Preferences > Keyboard > Input Sources. The delays are required for it to work but you could probably reduce their duration.
What this does is click the relevant menu and then type the first letters of the desired input. You may have to fiddle around with this depending upon what other items there are in your menu. It can work with a single letter but using a longer string, for example 'eng', helps avoid confusion. It then types the 'return' key to set your choice. Using letters to select allows you to work around whatever order or current setting is.
tell application "System Events"
tell application process "SystemUIServer"
click menu bar item 6 of menu bar 1
delay 0.3
keystroke "e"
delay 0.3
keystroke return
end tell
end tell

Related

How can I turn a popup menu invisible?

I'm working with Progress release 11.6, appBuilder and procedure editor.
I'm creating a new window, based on another one. That other window contains a browser, on which a popup menu is attached.
In my copy I don't want to see the popup menu at this moment (in other words, I'd like to disable it, so that the user does not see it).
I have tried putting VISIBLE to FALSE, HIDDEN to TRUE, but I'm always getting into problems.
My code looks as follows, does anybody know how I can turn the popup-menu invisible?
DEFINE MENU popup-menu-browser
MENU-ITEM m_Copy LABEL "Copy" ACCELERATOR "CTRL-C"
MENU-ITEM m_Cut LABEL "Cut" ACCELERATOR "CTRL-X"
...
browser-object:POPUP-MENU = MENU popup-menu-browser:HANDLE
// not working:
MENU POPUP-MENU-browser:HIDDEN = TRUE.
You need to remove the popup-menu:
MENU POPUP-MENU-browser = ?.
Or make it insensitive:
MENU POPUP-MENU-browser:SENSITIVE = FALSE.
Complete example:
define browse br with size 40 by 10.
define menu mb
menu-item mhide label "Hide"
.
on choose of menu-item mhide do:
browse br:popup-menu:sensitive = false.
end.
on " " anywhere do:
browse br:popup-menu:sensitive = true.
end.
browse br:popup-menu = menu mb:handle.
define frame fr
br
with
size 42 by 12
view-as dialog-box
.
enable all with frame fr.
view frame fr.
wait-for close of frame fr.
Beware that when switching between popup menus, you will lose the values of check boxes - see knowledge base article 000054795

Workspace Configuration Buttons missing in Xcode 12

In previous versions of Xcode, the workspace configuration buttons hide or show the optional navigator, debug, and utilities areas as shown in the Apple Docs here. They are missing in Xcode 12. Does anyone know if there is a way to make them reappear. I know that there are keyboard shortcuts for this functionality, but I have really grown accustomed to using the buttons.
All of these options are still available on xCode 12.
Workspace configuration buttons are moved to their respective sides.
Top right, top left and bottom debug area (If not visible then show from Menu bar > View > Show Toolbar & Menu bar > View > Debug Area > Show Debug Area)
The optional navigation and Editor configuration buttons are also there

how to view two dialog box on the linux console? running on the same time?

I want to view on the Linux console two dialog windows on the same time
one window that view the progress BAR
and the second tailbox that view the logs are running.
The problem is that the dialog present in the central of the console
What I want is to view the two dialog boxes on the same time on the console while the progress BAR is on the top of the screen
and the tail BOX should present down in the screen.
How to implement this?
How to place the dialog window up or down and not in the center ?
dialog --title "RUN TASKS FROM TEXT TABLE" --gauge "Please wait..." 10 70 0
dialog --tailbox file.log 10 100
You might be able to get this to work, using --tailboxbg, followed by --and-widget and then --gauge. The positioning of the widgets is straightforward, using the --begin option. The complication is in handling input from the keyboard: dialog makes a special case for allowing multiple -tailboxbg options by polling input across the corresponding windows. That polling "works" for similar widgets (which have input), but --gauge does not use input from the keyboard.

How to add custom options menu when Right Click on edit tool - Livecode

I want to create object and I want to add custom options menu when Right Click on edit tool.
This image :
I want to add custom menu on top "Edit Script"
How do I do ?
Not sure what you really are asking. When you right-click on an object, the IDE throws up a menu because it invokes the command: revPopUpMenu. Try this, just put the command in a button script.
If you want to make this your own, without hacking the IDE menu, then why not use a normal click and show a pullDown menu instead. You can populate the menu items as you wish, including especially the ability to populate on the fly based on the object clicked on, or any other attributes that might be local to that object or event.
Craig Newman
Here's an example to add to the IDE's context menu - originally posted on the livecode forums. There's also an example stack you can download : http://forums.runrev.com/viewtopic.php?f=9&t=18613
# catch the IDE's context menu message
on revHookBuildObjectEditorContextMenu pMenuTarget, pMenuName, #pMenu, pModifiedMenu
# custom menu item
put "Custom Item" & "-" & LF before pMenu
pass revHookBuildObjectEditorContextMenu
end revHookBuildObjectEditorContextMenu
# catch the IDE's message when an item is selected from the context menu
function dispatchContextMenuPick pMenuName, pItem
switch word 1 to -1 of pItem
case "Custom Item"
answer "Custom Item Selected"
exit to top
break
end switch
pass dispatchContextMenuPick
end dispatchContextMenuPick
To get it to work, put the code above into a button then use;
insert the script of button "MyFrontScript" into front

AutoIT: Problems using WinMenuSelectItem through multiple levels of menus

I'm having troubles using WinMenuSelectItem to select a menu option when I have to go through more than two levels of a menu.
The menu item I'm currently working with has this set up:
Menu Level 1
(click on item on Menu Level 1 to access) Menu Level 2
(hover over item on Menu Level 2 to access) Menu Level 3
I am able to use WinMenuSelectItem to do this operation just fine:
Menu Level 1
(click on item on Menu Level 1 to access) Menu Level 2
select item on Menu Level 2
I am unable to use WinMenuSelectItem to perform the following operation:
Menu Level 1
(click on item on Menu Level 1 to access) Menu Level 2
(hover over item on Menu Level 2 to access) Menu Level 3
select item on Menu Level 3
In my case, the text was something like "Open&&File".
It was actually "Open &File". The reason for this is that the menus are supposed to be easily accessible by a keyboard. You can press alt (to open the menu) and then the 'f' key, and it will act as if you had pressed 'Open File'.
The ampersand before the character here indicates the preferred shortcut. This is because it's possible to have multiple menus starting with the same characters. Example:
Open file
Open directory
Exit
In this case, the first two menu items are both given the shortcut 'o' for 'Open'. This is inconvenient for people who use your application a lot and wish to have simple shortcuts to do common operations. To give the menu items different shortcuts, you write them down like this:
Open &file
Open &directory
E&xit
It works the same for every menu item. Even for the top level menus.
Try it on notepad! Alt + F (&File) + x (E&xit).

Resources