Posted: 10th May, 2013
If you have multiple accounts on your mac, you may sometimes wish to log out one or more of those accounts without actually having to sign in to them first via the fast user switching menu. There’s a couple of ways to do this. First, if the issue is just that you want to shutdown the computer, you can log out all users by entering an Admin user name and password when this dialogue automatically appears after hitting ‘Shutdown’ (it won’t appear if no other users are logged on):
However, there are times when you may just want a quick way to log out users without shutting down and without wasting time logging in to their accounts first. Be aware that in killing a user’s process without logging in to the account first, any data in that user’s account that is not already saved (or autosaved) will be lost. If you’re sure that’s not a problem, then follow this short procedure manually or use the AppleScript version that follows:
1. Open up Activity Monitor (/Applications/Utilities/Activity Monitor.app)
2. Use the drop down menu in the Task bar to change the menu to ‘Other User Processes’ (note: you can use ‘All Processes’ in the menu if you wish, but that is less safe as it makes it possible to accidentally click on your own user process in step 4 below!).
3. In the filter bar, type
4. From the list of users that show up, for each one that you wish to log out:
- click on its row in the Activity Monitor pane to highlight the process
- press the ‘Quit Process’ icon in the Task bar above
- from the resulting dialogue window, click ‘Force Quit’
- supply an Admin password if requested.
Repeat for any further accounts that you wish to quit. (Tip: If you want to kill the ‘Guest User Account’, you’ll need to switch back to ‘All Processes’ and kill the loginwindow assigned to the ‘root’ user).
And that’s it. Your unwanted users are now logged out! 🙂
Update 30th April, 2016: If you get tired of doing this manually, you can log out all other real users at once with this AppleScript:
set thisUser to do shell script "whoami"
set usrList to paragraphs of (do shell script "ps caux -o args | grep loginwindow")
repeat with i from 1 to number of items in usrList
set this_item to item i of usrList
set thatUser to word 1 of this_item
if thisUser is not equal to thatUser then
set theProcessNum to word 2 of this_item
do shell script "kill -9 " & theProcessNum with administrator privileges
Update: I’ve recently written a Cocoa-app that includes this function. Take a look at OSXClock here. 🙂
It will create and keep a running log file (called ‘log.txt’) on your Desktop indicating which apps have been in focus on your machine and for how long each time. This could be ideal if you want to keep track of how long you spend working on a particular project either for billing a client or just for checking your own productivity.
How to use:
Open AppleScript Editor and paste the text below into the Editor window. Click the ‘run’ button. When you’ve had enough click the ‘stop’ button. It would be possible to automate running and stopping this, but I’ll leave that for the comments or maybe a later post.
*Note: be sure to click out of the app you’re using and activate Finder before you put the machine to sleep, otherwise the log will include the sleep time in the app’s duration
--start of script
set front_app to (path to frontmost application as text)
set _start to current date
set current_app to (path to frontmost application as text)
if current_app is not equal to front_app then
set _stop to current date
do shell script "echo " & front_app & " was active from " & _start & " until " & _stop & " >> ~/Desktop/log.txt"
set front_app to current_app
set _start to current date
--end of script
You will see the log looks something like this:
Seagate DP1:Applications:Utilities:AppleScript Editor.app: was active from Monday, 17 June 2013 17:20:30 until Monday, 17 June 2013 17:20:35
Seagate DP1:Applications:Adobe InDesign CS6:Adobe InDesign CS6.app: was active from Monday, 17 June 2013 17:20:35 until Monday, 17 June 2013 17:21:15
Seagate DP1:Applications:TextWrangler.app: was active from Monday, 17 June 2013 17:21:15 until Monday, 17 June 2013 17:21:25
Seagate DP1:Applications:Adobe InDesign CS6:Adobe InDesign CS6.app: was active from Monday, 17 June 2013 17:21:25 until Monday, 17 June 2013 17:24:46
Seagate DP1:Applications:TextEdit.app: was active from Monday, 17 June 2013 17:24:46 until Monday, 17 June 2013 17:26:26
Seagate DP1:Applications:Safari.app: was active from Monday, 17 June 2013 17:26:26 until Monday, 17 June 2013 17:45:03
Seagate DP1:Applications:Adobe InDesign CS6:Adobe InDesign CS6.app: was active from Monday, 17 June 2013 17:45:03 until Monday, 17 June 2013 17:46:03
Seagate DP1:Applications:TextEdit.app: was active from Monday, 17 June 2013 17:46:03 until Monday, 17 June 2013 17:46:13
On subsequent runs, you can keep the same log (the script will continue to add to the log on each run) or roll it over by renaming the log.txt on the Desktop and saving it off to somewhere else. If you rename or move the log.txt, then the next time you run the script, it will create a fresh log.txt on your Desktop automatically.
Featured picture: My Work Desk by ~RianGonzales