views:

985

answers:

4

I have the following shell script registered in my "Login Items" preferences but it does not seem to have any effect. It is meant to launch the moinmoin wiki but only works when it is run by hand from a terminal window, after which it runs until the machine is next shut down.

#!/bin/bash
cd /Users/stuartcw/Documents/Wiki/moin-1.7.2
/usr/bin/python wikiserver.py >> logs/`date +"%d%b%Y"`.log 2>&1 &

I would really like the Wiki to be available after restarting so any help in understanding this would be appreciated.

+1  A: 

I don't know much about it, since I don't use login items. Just a suggestion, maybe try with applescript that calls those shell commands, and put that in Login Items.

Vasil
+4  A: 

Try using launchd. More info at http://www.macgeekery.com/tips/all_about_launchd_items_and_how_to_make_one_yourself

Marc Novakowski
+3  A: 

Some helpful links:

Mac OS X: Creating a login hook

Making Shell Scripts Start at Login or System Startup

See also Lingon for a front end, should you decide to use Launchd instead.

Jay
Thanks for the answer! Lingon is cool. It helps to visualize the settings and lets you get a feel for what you can do with launchd but in this case the basic mode was too basic for me as I wanted to set a working directory.
stuartcw
+1  A: 

launchd is one of the best parts of MacOS X, and it causes me great pain to not be able to find it on other systems.

Edit and place this in /Library/LaunchDaemons as com.you.wiki.plist

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"&gt;
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>com.you.wiki</string>
    <key>LowPriorityIO</key>
    <true/>
    <key>KeepAlive</key>
    <true/>
    <key>RunAtLoad</key>
    <true/>
    <key>Nice</key>
    <integer>1</integer>
    <key>WorkingDirectory</key>
    <string>/Users/stuartcw/Documents/Wiki/moin-1.7.2</string> 
    <key>UserName</key>
    <string>user to run this as</string>
    <key>ProgramArguments</key>
    <array>
        <string>/usr/bin/python</string>
        <string>wikiserver.py</string>
    </array>
</dict>
</plist>
Dustin
Full details are here: http://developer.apple.com/MacOsX/launchd.htmlI'm currently looking into putting it into my LaunchAgents folder. "If it is only useful when users are logged in, put it in /Library/LaunchAgents, or in the personal LaunchAgents directories of specific users."
stuartcw