![[personal profile]](https://www.dreamwidth.org/img/silk/identity/user.png)
![[community profile]](https://www.dreamwidth.org/img/silk/identity/community.png)
Okay, so I decided my life would be better if I factored it into multiple users on my regular box, which is a MacBook Pro running Catalina (10.15).
I turned on Fast User Switching, which I guess puts the user menu in the upper right? I find using menus to switch users really annoying. I want to switch users without taking my hands off the keyboard.
So I go looking for the keystroke shortcut for this, and rapidly discover there is none.
After a hell of a lot more searching, I discover this:
https://hints.macworld.com/article.php?story=20110813074611411
which is terrible because it stores the password in plaintext, but that's okay, I am willing to type out the password, but also terrible because AppleScript.
But this:
https://superuser.com/questions/44433/create-a-keyboard-shortcut-for-fast-user-switching-in-mac-os-x
Which points out you can just call the relevant thing from a shell script, only that flag doesn't work, possibly because that's an answer for a question in Snow Leopard (10.6.8).
But this:
https://blog.taylormcgann.com/tag/cgsession/
has information about flags for that command, and also explains how to use it with Automator. What the hell is Automator? What it sounds like.
So what I realized I wanted is a keystroke command that would not take me to the screen from which I could select another user, because mouse, but would take me to the screen with a specific user selected and prompting me for a password. This means I need to do this for each user I want to switch to, times how many users I have minus 1. I have two user accounts, so I had to do this twice.
To do this, you need the magic command, and you need to call it on your user id's number. To get this number, use the command embedded in that above Apple Script: /usr/bin/id -u + whatever username you want to switch to.
When you fire up Automator and prod it to make you a new Automator thing, the correct option for this purpose is a new "Quick Action", because Quick Actions are/can be (?) Services. And Services can be assigned to Finder keystroke shortcuts.
So create a new "Quick Action", and in the third pane, the first option is "Workflow received current" and a pull down menu. Choose "no input" all the way at the bottom. Then in the left pane, select, under Library, "Utilities"; in the middle pane, find "Run Shell Script" and drag it into the right pane. Pick a shell in the shell menu (when in doubt, /bin/sh) and in the textbox write:
I didn't do this. Instead, I ran /usr/bin/id -u YOURTARGETUSERNAMEHERE at the Terminal and then hard coded the returned number into the script, which looks like
Save this. Give it a name like "Switch to YOURTARGETUSERNAMEHERE". Note: I have no idea where in the filesystem it winds up. The important thing is that if you do this all correctly, you can now fire up System Preferences, go to Keyboard, select the Shortcuts tab, then in the left pane select Services, and then scroll the right pane all the way to the bottom, and there, under General, you should see "Switch to YOURTARGETUSERNAMEHERE". Assign it a keystroke combination that you can remember and find convenient and doesn't clash too bad with any used elsewhere (I used shift-command-s (for "switch") and promptly discovered it conflicts with Terminal's Save Selected Text) and – voila!
Now, go log into the other account, and do the same thing, only with the previous account as the target, there. You can use the same keystroke for both, because they won't clash.
You'll need more keystroke options, though, if you have three or more users to switch among. If you have three accounts, you'll want account A to have a keystroke for account B and another keystroke for account C, account B to have keystrokes for accounts A and C, and account C to have keystrokes for accounts A and B. Good luck.
I turned on Fast User Switching, which I guess puts the user menu in the upper right? I find using menus to switch users really annoying. I want to switch users without taking my hands off the keyboard.
So I go looking for the keystroke shortcut for this, and rapidly discover there is none.
After a hell of a lot more searching, I discover this:
https://hints.macworld.com/article.php?story=20110813074611411
which is terrible because it stores the password in plaintext, but that's okay, I am willing to type out the password, but also terrible because AppleScript.
But this:
https://superuser.com/questions/44433/create-a-keyboard-shortcut-for-fast-user-switching-in-mac-os-x
Which points out you can just call the relevant thing from a shell script, only that flag doesn't work, possibly because that's an answer for a question in Snow Leopard (10.6.8).
But this:
https://blog.taylormcgann.com/tag/cgsession/
has information about flags for that command, and also explains how to use it with Automator. What the hell is Automator? What it sounds like.
So what I realized I wanted is a keystroke command that would not take me to the screen from which I could select another user, because mouse, but would take me to the screen with a specific user selected and prompting me for a password. This means I need to do this for each user I want to switch to, times how many users I have minus 1. I have two user accounts, so I had to do this twice.
To do this, you need the magic command, and you need to call it on your user id's number. To get this number, use the command embedded in that above Apple Script: /usr/bin/id -u + whatever username you want to switch to.
When you fire up Automator and prod it to make you a new Automator thing, the correct option for this purpose is a new "Quick Action", because Quick Actions are/can be (?) Services. And Services can be assigned to Finder keystroke shortcuts.
So create a new "Quick Action", and in the third pane, the first option is "Workflow received current" and a pull down menu. Choose "no input" all the way at the bottom. Then in the left pane, select, under Library, "Utilities"; in the middle pane, find "Run Shell Script" and drag it into the right pane. Pick a shell in the shell menu (when in doubt, /bin/sh) and in the textbox write:
/System/Library/CoreServices/Menu\ Extras/User.menu/Contents/Resources/CGSession -switchToUserID `/usr/bin/id -u YOURTARGETUSERNAMEHERE`Only use your username instead of YOURTARGETUSERNAMEHERE.
I didn't do this. Instead, I ran /usr/bin/id -u YOURTARGETUSERNAMEHERE at the Terminal and then hard coded the returned number into the script, which looks like
/System/Library/CoreServices/Menu\ Extras/User.menu/Contents/Resources/CGSession -switchToUserID 501Hard coding the user number makes it slightly faster.
Save this. Give it a name like "Switch to YOURTARGETUSERNAMEHERE". Note: I have no idea where in the filesystem it winds up. The important thing is that if you do this all correctly, you can now fire up System Preferences, go to Keyboard, select the Shortcuts tab, then in the left pane select Services, and then scroll the right pane all the way to the bottom, and there, under General, you should see "Switch to YOURTARGETUSERNAMEHERE". Assign it a keystroke combination that you can remember and find convenient and doesn't clash too bad with any used elsewhere (I used shift-command-s (for "switch") and promptly discovered it conflicts with Terminal's Save Selected Text) and – voila!
Now, go log into the other account, and do the same thing, only with the previous account as the target, there. You can use the same keystroke for both, because they won't clash.
You'll need more keystroke options, though, if you have three or more users to switch among. If you have three accounts, you'll want account A to have a keystroke for account B and another keystroke for account C, account B to have keystrokes for accounts A and C, and account C to have keystrokes for accounts A and B. Good luck.