Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Need help with getting a login script to work with a login hook.

I have tried three methods to implement a login script on OS X 10.6.8 Snow Leopard. I am trying to get the third method to work because, if I understand correctly, it runs in the background without anything appearing on the screen.


The first method involves an AppleScript saved as an application that is added to the list of login items via System Preferences in the Accounts pane. When the account is logged in, an AppleScript icon briefly appears and disappears on the Dock.


The second method involves a Terminal shell script that is saved with the name “login.command”, made executable via the Terminal command line, and then is added to the list of login items via System Preferences in the Accounts pane. Using this method, when the account is logged in, a Terminal window opens.


The third method involves a login hook. It does not seem to work, although a similarly configured logout hook does work. This method uses a Terminal shell script also. The shell script is saved with the name “loginscript” in the folder at the location “/usr/local/bin”, and the script is made executable via the Terminal command line. Then, the below commands are run on the Terminal command line:


sudo defaults write com.apple.loginwindow LoginHook /usr/local/bin/loginscript


sudo defaults read com.apple.loginwindow


Might anyone know how to make the third method work? I can provide more details of what I have done, if necessary.

Posted on Jul 13, 2013 4:44 AM

Reply
9 replies

Jul 13, 2013 6:16 AM in response to Mark Jalbert

Regarding the code of the script, I tried two versions. Below is the first version:


#!/bin/bash

say "Hello, hello, hello. This is the startup script."


Below is the second version:


#!/bin/bash

#say "Hello, hello, hello. This is the startup script."

/usr/bin/osascript ~/Desktop/login_script.scpt


The AppleScript file “login_script.scpt” itself also has the "say" command in it.


Neither version produces any sound. Also, I double-checked the system volume to make sure that it was audible.

Jul 13, 2013 11:11 AM in response to John with a G4

NOTE: The loginhook environment is minimum


pwd: /


id -a:uid=0(root)
gid=0(wheel)
egid=80(admin)
groups=0(wheel),
1(daemon),
2(kmem),
8(procview),
29(certusers),
3(sys),
9(procmod),
4(tty),
5(operator),
80(admin),
20(staff)


$1: psmith


printenv: PWD=/
SHLVL=1
SECURITYSESSIONID=449a3aa0
_=/usr/bin/printenv


Notice, no PATH, no USER environment variables, just about

nothing as an environment.


So, the 'say' command will not be found.


You can try


/usr/bin/say "Hello, hello, hello. This is the startup script."


and see how that works

Need help with getting a login script to work with a login hook.

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.