TerminallyGeeky

Latest

  • Terminally Geeky: How to tell if a script is being called from launchd

    by 
    TJ Luoma
    TJ Luoma
    02.25.2013

    Warning: command line geekiness ahead. When writing shell scripts, I often send interactive output to the user via echo to give feedback or information. But if the shell script is called on a schedule via OS X's behind-the-scenes process launcher launchd, rather than from a Terminal session, chances are that I won't ever see that message. Fortunately, it's relatively easy to figure out if a shell script has been called from launchd or not, simply by checking the $PPID variable. (Note: this works in zsh and may work in bash as well. If it doesn't work in your shell, this is a good time to upgrade to zsh.) But how can I make sure my messages are seen if a shell script has been called via launchd? For that I use the Swiss Army Knife of notification tools, Growl. Specifically, I use the growlnotify optional package, which allows me to send Growl notifications from shell scripts. For example, imagine that I wrote a script where I wanted to tell the user that a certain process had succeeded or failed. Normally I might just use echo 'SUCCESS!' or echo 'FAILED!' But now, instead of 'echo' I use a function called msg (short for 'message'). If the script was called from launchd then msg will use growlnotify, but if the script was called from the command line, it will just use echo. Here's how that works: This method is not foolproof. For example, if you call a shell script from launchd and that shell script calls another shell script, it might not realize that it was originally executed from launchd. In practice, I have not run into that problem, but it did seem worth mentioning.

  • Terminally Geeky: use automatic login more securely

    by 
    TJ Luoma
    TJ Luoma
    03.07.2011

    Imagine if you rebooted your computer, and it automatically logged you in, launched all of your login apps, updated your Dropbox folder, MobileMe, email, RSS, Twitter and everything else without you even having to enter your password. That auto-login capability is built into your Mac, and in fact, it may be the default setting on your Mac, so this may be how you're used to operating. But if you're like me, you disabled auto-login for security reasons, so when you reboot your Mac, it stops at the login screen, waiting for you to enter (or click on) your login name and enter your password. What if you could have both? What if you could have the security of the login screen with the convenience of automatic login? That's what I'm going to show you how to do.

  • Terminally Geeky: Deadline reminders using Growl, sleepwatcher, and GNU date

    by 
    TJ Luoma
    TJ Luoma
    02.18.2011

    When I have a large deadline looming, I like to keep track of how many days I have left. I've tried Dashboard widgets, iPad apps and just about anything else you could think of, but they all have failed for one simple reason: they require me to check them. I can go days or weeks without triggering the Dashboard, and an iOS countdown app still requires that you check it. I could use something like Due app, but I really don't want something actively distracting me -- I want something passively reminding me. Nor do I want these cluttering up my iCal. I found my solution by cobbling together several bits of free Unix utilities that are essential to any true geek's tool belt.