Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

Is it possible to run a script when and only when a user is logged out? Why I want to do this is so I can change the login message (sudo defaults write /Library/Preferences/com.apple.loginwindow LoginwindowText "Message"). Is there a way to do this?

share|improve this question
1  
Do you mean "upon logout" or "while logged out"? –  JRobert Mar 20 '12 at 20:31
    
@JRobert While logged out –  CoffeeRain Mar 20 '12 at 20:52
    
1  
See Make a script/app run on logout. –  Mathias Bynens Mar 21 '12 at 11:07

3 Answers 3

up vote 1 down vote accepted

Machints has got a sample script available here to write the logon and logoff events to a log file.

You basically need to write your script, give it execute rights and then add it to the LogoutHook event:

sudo defaults write com.apple.loginwindow \ LogoutHook /usr/local/bin/logoutscript

For some more advanced script you can also have a look here

Alternative solution

Have a look at the launchd services. It's the built in service management system used by OSX. Some suggestions are to have launchd monitor a file, and using the logoutHook above, touch the file, which will trigger launchd to run. In the launchd job you can sleep the process for a few seconds to ensure that logout is completed.

Not the ideal solution, but could work.

share|improve this answer
    
That wasn't what I was looking for. Instead of running while I was logged off, it ran while I was logging off. –  CoffeeRain Mar 20 '12 at 20:53
    
@CoffeeRain Added a potentail workaround. Not entirely sure how vaiable it but worth investigating. –  Diago Mar 20 '12 at 21:11
    
Thanks for the help! –  CoffeeRain Mar 21 '12 at 14:03

See here for how to run a script: How can I run/stop/relaunch an application automatically, at boot/login/some other time?

Have your script check if user logged in. If yes, exit. If no, do your thing.

share|improve this answer

You can change your login screen text, no need to run a script if this is a one-time or infrequent change. You have to add the key

enter image description here

to /Library/Preferences/com.apple.loginwindow.plist either with a text editor or by a terminal command which does the same thing. This article describes both ways.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.