Switch to a specific input source in OS X in Catalina with AppleScript I use different keyboard layouts and switched between them using a simple script 

on changeKeyboardLayout(layoutName)
    tell application "System Events" to tell process "SystemUIServer"
        tell (1st menu bar item of menu bar 1 whose description is "text input") to {click, click (menu 1's menu item layoutName)}
    end tell
end changeKeyboardLayout
changeKeyboardLayout("German LaTeX2")


That worked well until the latest update.
I don't really speak AppleScript, but a bit of testing indicates that SystemUIServer no longer has access to a menu item with name "text input". 
Trying

tell application "System Events" to tell process "SystemUIServer" to get value of attribute "AXDescription" of every menu bar item of menu bar 1


gives me Siri, blutooth, time machine, clock and a few others. So somehow the input source menu is managed differently now, but I have now clue how or how to find out (all searches pointed me to scripts similar to mine)

Update 2019/12/10

The suggested solutions so far both have defects, in one case you always get a delay of 5 seconds which is rather long and the trick with killing  "System Events" as taken from the other posting doesn't always seem to work, sometimes it results in the script getting a timeout (which is even worse then have the 5 seconds delay all the time), so it looks as if this is still in need for a better solution
Unfortunately things have changed in macOS Catalina and you''ll have to activate that menu in a different manner.

The following example AppleScript code, shown further below, works for me in macOS Catalina, however as I was testing in a virtual machine I do not know if the time lag in the running of the code, between clicking the target menu and the subsequent code, is inherent of an issue in the virtual machine or it will be the same on a physical machine.

I do not have German LaTeX2 so I used German instead, although for convenience I have replaced it in the code after testing.

The usual caveats apply for the use of this in: System Preferences > Security &amp; Privacy > Privacy > Accessibility

Example AppleScript code: 

tell application "System Events" to ¬
    tell application process "TextInputMenuAgent" to ¬
        tell menu bar item 1 of menu bar 2
            click
            click menu item "German LaTeX2" of menu 1
        end tell


This does the same thing in a different manner, and one of these ways may be faster.

tell application "System Events" to ¬
    tell application process "TextInputMenuAgent" to ¬
        click menu bar item 1 of menu bar 2

tell application "System Events"
    keystroke "g"
    key code 36
end tell


To use the example AppleScript code in a handler:

changeKeyboardLayout("German LaTeX2")

on changeKeyboardLayout(layoutName)
    tell application "System Events" to ¬
        tell application process "TextInputMenuAgent" to ¬
            tell menu bar item 1 of menu bar 2
                click
                click menu item layoutName of menu 1
            end tell
end changeKeyboardLayout


Or the second version of the code:

changeKeyboardLayout("German LaTeX2")

on changeKeyboardLayout(layoutName)
    tell application "System Events" to ¬
        tell application process "TextInputMenuAgent" to ¬
            click menu bar item 1 of menu bar 2
    tell application "System Events"
        keystroke (first text item of layoutName)
        key code 36
    end tell
end changeKeyboardLayout




Note: The example AppleScript code is just that and does not contain any 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.