5

What I want is to send a URL with variables to a server which will track when someone is present based on when they login and logout of their workstation.

I've tried setting the LoginHook in com.apple.loginwindow to "/Users/Username/Desktop/script.sh". script.sh works when I execute it myself from the terminal, but it doesn't run from the LoginHook.

The script executes the following, where $USER should be the name of the user currently logged in:

curl -kd "author=$USER&type=inout&message=in" https://some.server.com/timetrack
slhck
  • 235,242
bernk
  • 225

1 Answers1

2

Using a LoginHook and LogoutHook as described in How to run a script at login/logout in OS X? would probably be the easiest approach. It's considered deprecated but works until 10.8 and might even work beyond that.

Make sure your script has a correct hashbang so the launching process will know how to execute it. After all your script could be anything from Ruby to Python or simply Bash.

So, for example:

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

And /usr/local/bin/curl.sh being:

#!/bin/bash
curl -kd "author=${1}&type=inout&message=in" https://some.server.com/timetrack

To access the user who is logging in, you need to use $1 instead of $USER because the latter is a variable that only exists in an actual shell environment, which doesn't exist if you use login scripts.

slhck
  • 235,242