Blog - On the importance of early mornings and Applescript return codes

  • Home
    • Blog - On the importance of early mornings and Applescript return codes

On the importance of early mornings and Applescript return codes

Well, it’s 6.45am and I’m sat in a deserted college listening to Planet Rock and fixing broken AppleScript - this shit just isn’t funny any more.

If I blog this hopefully it’ll get Googled and possibly save someone else losing a night’s sleep!

I’ve implemented a login hook this year on the OS X build this year, as per Apple’s doc here: http://docs.info.apple.com/article.html?artnum=301446 A login hook allows you to run a custom script every time a user logs in, which is useful for clearing out temporary areas, mounting drives and so on. The important part to note on the doc is:

"Other login actions wait until the hook has completely executed."

Now, that isn’t stictly true! What they mean by ‘login actions’ doesn’t seem to actually include logging in! In other words, if your script isn’t exiting cleanly the user can appear to login fully but some behind the scenes login action can fail to run, i.e. loginwindow.plist .

As per the instructions I set my ‘login.sh’ script as the login hook, which is as follows:


if [ "$1" != "admin" ]
then
/login/mountGlobal.app
rm -rf /User\ Work/*
echo `date` "$1 logged in (cleared User Work)" >> /Library/Logs/lcad.log
fi

The mountGlobal.app source being the following:


tell application "Finder"
mount volume "smb://dali.academic.lcad/Student_Area"
end tell

The problem here is that the Applescript seems not to give a clean exit code, or the bash script doesn’t understand it. Either way the login.sh script doesn’t exit cleanly and hence other login actions are not run, i.e. /Library/Preferences/loginwindow.plist isn’t interpreted.

This means that all the apps that are supposed to run at login from that script (Sophos, K2, Adobe Bridge, Print Control etc.) don’t run. The answer in this case is to simply change line 3 to ‘/login/mountGlobal.app &’, the ampersand forcing the Applescript to run ansynchronously and allowing login.sh to exit cleanly. It’s a bit hacky, but at this time of the morning I don’t care!

Leave a Reply