Help running script at startup...tried LoginHook.

Discussion in 'macOS' started by GNice, Dec 17, 2007.

  1. GNice macrumors 6502

    Joined:
    Aug 7, 2007
    #1
    I have a very simple (one line) shell script that does nothing but create a symbolic link. I've given it execute permissions and tested it. Works like a charm from the command line. Being still pretty new to the mac world I googled around and it appears LoginHook is the way to get a script to run at start up. I followed the instructions found here: http://docs.info.apple.com/article.html?artnum=301446

    Tried both approaches...with no success.

    I also tried the tool located here: http://www.bombich.com/mactips/loginhooks.html

    I got a few messages about not being able to find certain files, but the UI came up and I was able to point to my script test it and it worked. But once again after a reboot, my script didn't run at log in.

    Anyone have any idea if LoginHook still works in Leopard (all info I could find was pre-Leopard). Any other suggestions on how to get a shell script to run at start up.

    Thx!
     
  2. wrldwzrd89 macrumors G5

    wrldwzrd89

    Joined:
    Jun 6, 2003
    Location:
    Solon, OH
    #2
    A work-around is to save the shell script as a command file (example: login.command), make it executable, then add it to your Login Items in System Preferences -> Accounts pane.
     
  3. GNice thread starter macrumors 6502

    Joined:
    Aug 7, 2007
    #3
    Thx soooo much! Worked like a charm. Now as I final touch if I can just "automatically" close the terminal window that gets launched when the script is run I will be golden.

    Too bad the LoginHook isn't working, but I definitely appreciate your help!
     
  4. wrldwzrd89 macrumors G5

    wrldwzrd89

    Joined:
    Jun 6, 2003
    Location:
    Solon, OH
    #4
    That's easy too. Just add the following line to the end of your script:
    Code:
    killall Terminal
    You may get a warning from the Terminal that stuff is running, but you're probably going to want to disable that. I've attached a couple of screenshots. The first one is the default settings in Leopard's Terminal. The second one is what you want the settings to look like.
     
  5. weatherman macrumors newbie

    Joined:
    Dec 19, 2007
    #5
    You can close the terminal window without closing the whole program by using a simple AppleScript:

    Code:
    osascript -e 'tell app "Terminal" to close every window whose frontmost is true' &
    This works from the terminal.

    Bonus:
    If you've got scripts etc. that keep running all the time you can easily turn them into "daemons" with GNU screen utility

    Code:
    screen -dmS "Name" /path/to/script.something
    After this command it's safe to close the whole terminal and the script keeps still running.

    Name is for indentification purposes only, if you've got multiple screens running it's useful. leave -S away if you don't wanna spefify a name.

    Ville
     
  6. wrldwzrd89 macrumors G5

    wrldwzrd89

    Joined:
    Jun 6, 2003
    Location:
    Solon, OH
    #6
    Thank you! I did not know you could do this - I write shell scripts myself, and this capability will be very useful for me.
     
  7. GNice thread starter macrumors 6502

    Joined:
    Aug 7, 2007
    #7
    Thx a million wrldwzrd89 and weatherman!!! You both have helped me a ton!!!
     

Share This Page