<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.afp548.com/index.php?action=history&amp;feed=atom&amp;title=Login%2FLogout_Hooks_in_OS_X</id>
	<title>Login/Logout Hooks in OS X - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.afp548.com/index.php?action=history&amp;feed=atom&amp;title=Login%2FLogout_Hooks_in_OS_X"/>
	<link rel="alternate" type="text/html" href="https://wiki.afp548.com/index.php?title=Login/Logout_Hooks_in_OS_X&amp;action=history"/>
	<updated>2026-11-04T10:55:10Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.34.0</generator>
	<entry>
		<id>https://wiki.afp548.com/index.php?title=Login/Logout_Hooks_in_OS_X&amp;diff=939&amp;oldid=prev</id>
		<title>Bw38: Created page with &quot;This article will describe Login and Logout hooks and how to create them. __FORCETOC__ ==Create Log In/Out Hook== Before proceeding, note that if you do not have a password, y...&quot;</title>
		<link rel="alternate" type="text/html" href="https://wiki.afp548.com/index.php?title=Login/Logout_Hooks_in_OS_X&amp;diff=939&amp;oldid=prev"/>
		<updated>2013-05-26T21:41:48Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;This article will describe Login and Logout hooks and how to create them. __FORCETOC__ ==Create Log In/Out Hook== Before proceeding, note that if you do not have a password, y...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;This article will describe Login and Logout hooks and how to create them.&lt;br /&gt;
__FORCETOC__&lt;br /&gt;
==Create Log In/Out Hook==&lt;br /&gt;
Before proceeding, note that if you do not have a password, you will need to create a password on your account for this to work.&lt;br /&gt;
&lt;br /&gt;
#Open Terminal (Applications/Utilities).&lt;br /&gt;
#In the Terminal window, for Log In Hooks type&amp;lt;br /&amp;gt;&amp;lt;code&amp;gt;sudo defaults write com.apple.loginwindow LoginHook &amp;#039;&amp;#039;&amp;#039;/path/to/script&amp;#039;&amp;#039;&amp;#039;&amp;lt;/code&amp;gt;&amp;lt;br /&amp;gt;Where &amp;#039;&amp;#039;&amp;#039;/path/to/script&amp;#039;&amp;#039;&amp;#039; is the full path to the script that you want to execute when a user logs in—it doesn&amp;#039;t have to be in the user&amp;#039;s Home directory.&lt;br /&gt;
#In the Terminal window, for Log Out Hooks type&amp;lt;br /&amp;gt;&amp;lt;code&amp;gt;sudo defaults write com.apple.loginwindow LogoutHook &amp;#039;&amp;#039;&amp;#039;/path/to/script&amp;#039;&amp;#039;&amp;#039;&amp;lt;/code&amp;gt;&amp;lt;br /&amp;gt;Where &amp;#039;&amp;#039;&amp;#039;/path/to/script&amp;#039;&amp;#039;&amp;#039; is the full path to the script that you want to execute when a user logs in—it doesn&amp;#039;t have to be in the user&amp;#039;s Home directory.&lt;br /&gt;
#This modifies the &amp;#039;&amp;#039;&amp;#039;/var/root/Library/Preferences/com.apple.loginwindow&amp;#039;&amp;#039;&amp;#039; file.&lt;br /&gt;
#Type your password at the prompt, then press Return.&lt;br /&gt;
&lt;br /&gt;
==Remove Log In/Out Hook==&lt;br /&gt;
Before proceeding, note that if you do not have a password, you will need to create a password on your account for this to work.&lt;br /&gt;
#Open Terminal (Applications/Utilities).&lt;br /&gt;
#In the Terminal window, for Log In Hooks type&amp;lt;br /&amp;gt;&amp;lt;code&amp;gt;sudo defaults delete com.apple.loginwindow LoginHook &amp;#039;&amp;#039;&amp;#039;/path/to/script&amp;#039;&amp;#039;&amp;#039;&amp;lt;/code&amp;gt;&amp;lt;br /&amp;gt;Where &amp;#039;&amp;#039;&amp;#039;/path/to/script&amp;#039;&amp;#039;&amp;#039; is the full path to the script that you want to execute when a user logs in—it doesn&amp;#039;t have to be in the user&amp;#039;s Home directory.&lt;br /&gt;
#In the Terminal window, for Log Out Hooks type&amp;lt;br /&amp;gt;&amp;lt;code&amp;gt;sudo defaults delete com.apple.loginwindow LogoutHook &amp;#039;&amp;#039;&amp;#039;/path/to/script&amp;#039;&amp;#039;&amp;#039;&amp;lt;/code&amp;gt;&amp;lt;br /&amp;gt;Where &amp;#039;&amp;#039;&amp;#039;/path/to/script&amp;#039;&amp;#039;&amp;#039; is the full path to the script that you want to execute when a user logs in—it doesn&amp;#039;t have to be in the user&amp;#039;s Home directory.&lt;br /&gt;
#This modifies the &amp;#039;&amp;#039;&amp;#039;/var/root/Library/Preferences/com.apple.loginwindow&amp;#039;&amp;#039;&amp;#039; file.&lt;br /&gt;
#Type your password at the prompt, then press Return.&lt;br /&gt;
&lt;br /&gt;
==Examples==&lt;br /&gt;
===Clear Home Directory on Log Out===&lt;br /&gt;
This script is called &amp;#039;&amp;#039;&amp;#039;clrlogout.sh&amp;#039;&amp;#039;&amp;#039; used in a Lab and deletes all user account folders that are not named &amp;quot;admin&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
 #!/bin/bash&lt;br /&gt;
 if [ $1 = &amp;quot;admin&amp;quot; ]&lt;br /&gt;
     then exit 0&lt;br /&gt;
 fi&lt;br /&gt;
 &lt;br /&gt;
 #Deletes the user account and its local home directory&lt;br /&gt;
 dscl . -delete /Users/$1 #deletes the user from System Preferences&lt;br /&gt;
 rm -R /Users/$1 #deletes the user&amp;#039;s local home directory&lt;br /&gt;
 &lt;br /&gt;
 exit 0&lt;br /&gt;
&lt;br /&gt;
This script can be amended to not delete other user home directories as well. This script is placed in the folder &amp;#039;&amp;#039;&amp;#039;/Library/Scripts/Company&amp;#039;&amp;#039;&amp;#039;. When applying it as a logout hook, type the command in Terminal:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;#039;&amp;#039;&amp;#039;sudo defaults write com.apple.loginwindow LoginHook /Library/Scripts/Company/clrlogout.sh&amp;#039;&amp;#039;&amp;#039;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
*http://support.apple.com/kb/HT2420&lt;br /&gt;
*http://developer.apple.com/library/mac/#documentation/MacOSX/Conceptual/BPSystemStartup/Chapters/CustomLogin.html&lt;br /&gt;
*http://www.mactech.com/articles/mactech/Vol.25/25.07/2507MacEnterprise-Scriptingopportunities2/index.html&lt;br /&gt;
*http://krypted.com/mac-os-x/login-logout-hooks/&lt;br /&gt;
&lt;br /&gt;
[[Category:Scripts]]&lt;/div&gt;</summary>
		<author><name>Bw38</name></author>
		
	</entry>
</feed>