Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

stuart1231

macrumors newbie
Original poster
Sep 25, 2006
13
0
Hello,

I am trying to build a niche social network site and was wondering if it is possible to create a tiny program on the mac which would access a web address on startup to e.g. say the user is at their computer, rather than having to login (if they wished). For example query http://www.testing.com?login=stu

And on shutdown http://www.testing.com?logout=stu

I am sorry if this is not specific enough, but what would be the best plan of action, I am experience in Web Programming but not Mac.

Stu
 

numero

macrumors regular
Jul 23, 2002
106
3
OR
I think you need two things here.

1) A way to issue the URL request. I think this can be done with the "curl" command line utility. Make a script called login.sh that looks something like:

Code:
#!/bin/sh
curl http://www.testing.com/?login=stu > /dev/null

Make another one called logout.sh. These can be put anywhere in the user's home directory.

2) A way to trigger them at the right time.

There are two ways to get something to trigger at login. You can use a plist file setup with launchd or you can make a LoginHook in com.apple.loginwindow.

I'd say that the launchd method is the preferred way. Look up the specifics on launchd, but the short version is to make a plist file and put it in ~/Library/LaunchAgents. Launch agents get triggered whenever a user logs in.

The only way I know of letting OS X trigger something upon logout is through making a LogoutHook in com.apple.loginwindow. Read the following link and pay attention to a couple of caveats. 1) ~/Library/Preferences/com.apple.loginwindow must already exist for the "defaults" command to work. If the file doesn't exist then you must provide a basic starting point. 2) There can only be a single entry for each of LoginHook and LogoutHook. If something on the system is already using that key then you will be deleting that entry and inserting your own.

Lookup defaults.
http://developer.apple.com/document...omLogin.html#//apple_ref/doc/uid/20002134-SW1

You will need to do

Code:
defaults write com.apple.loginwindow LogoutHook /path/to/logout/script

Don't do sudo like the web page shows. You want the user's ~/Library/Preferences/com.apple.loginwindow to be changed, not the /Library/Preferences/... one.

Another possibility is to write a small application that gets triggered by launchd upon the user's login. This application does your login task and then sits idle until it gets a quit command. Right before it quits it sends your logout signal to the server.

I don't think that this last option is that hard to do. Let me know if the other options fall through and I might dig into trying to code this.

--numero
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.