How to use a keyboard shortcut to switch keyboard layouts in OSX

I use the Dvorak keyboard layout, which is great but problematic when, for example, I have a coworker who needs to type something on my machine. It got tedious clicking through options to change the keyboard layout, so I created a hotkey to do this. Go to System Preferences -> Keyboard -> Shortcuts. Select “Input Sources” from the menu, then check the “Select the previous input source” box. For some reason, it defaults to Cmd + Space, which is the same hotkey that Spotlight uses. I use Alfred, which activates with Option + Space, so it wasn’t a problem for me to just disable Spotlight’s hotkey. If you do use Spotlight, you can customize the hotkey in the same window.