launchd

Latest

  • How to keep Homebrew and XQuartz updated automatically

    by 
    TJ Luoma
    TJ Luoma
    06.11.2014

    If you use Homebrew (and you should), eventually you may need to install XQuartz, "open-source effort to develop a version of the X.Org X Window System that runs on OS X. Together with supporting libraries and applications, it forms the X11.app that Apple has shipped with OS X since version 10.5." The trouble is that brew won't install XQuartz, and it won't update it once it is installed, but it will complain if it isn't installed or is out of date. What I needed was a way to install it, if it isn't installed, or update it if it is out of date. Also, brew is constantly being updated, which means that you should update it every day. Something you need to do every day? Do I even need to say "automation"? Wait. I said it... but you would have guessed it. I have faith in you. There are three parts of this: 1) a shell script to update XQuartz, 2) a shell script to update brew, and 3) a launchd plist the run the script. You could combine #1 and #2 into one if you want, but I like keeping them separate. launchd Let's start with the easiest part: I want this to run automatically when my satellite quota is loosened, so I have a launchd plist to run my shell script at 3:03 a.m. every day: Why 3:03 a.m.? Because my quota is loosened between 2:00 a.m. and 8:00 a.m., but I don't want to have to worry about Daylight Saving Time, so after 3:00 a.m. seemed like the best way to do that. The Shell Script(s) The updatebrew.sh script has two pieces. The first is di-xquartz.sh which will (d)ownload and (i)nstall XQuartz: Another detail: if you want to be able to run that script without needing to enter your administrator password, you'll need to add this line to /etc/sudoers using sudo visudo: %admin ALL=NOPASSWD: /usr/sbin/installer The only time you should do this is if you are the only administrator user on your Mac, or if you understand the risks. Next you need to run the two commands to update brew and any outdated brew utilities: brew update and brew upgrade, followed by brew doctor to make sure everything is OK. You want it simple? All you really need is this: Note that this script includes the di-xquartz.sh as well as the brew commands. That's pretty bare-bones, but it'll get the job done. Just be sure to check the log file. If you want something a little more (robust? complicated?), you could send the log to your iPhone using Pushover. As my Computer Science professor used to say, "the rest is left as an exercise for the reader."

  • Terminally Geeky Time Tracking via Screenshots

    by 
    TJ Luoma
    TJ Luoma
    08.02.2013

    A few weeks ago I shared this on Twitter: "Here's an eye-opener: a @keyboardmaestro macro which takes a screenshot every 30 seconds. Review at the end of the day to see where it went." Since then, several people have asked me to share my setup (and a few said it terrified them). It took me a while to refine it, but I think I finally found a setup that will work for me. The "Why" The problem is simple: at the end of the day, I often feel like I accomplished a lot, but can't remember everything I worked on; or, I feel like I was busy all day, but don't have much of a sense of what I actually did. In both cases, it would be helpful to be able to 'rewind' my day and be reminded of what I did. The big problem is distractions, either internal or external. I find myself going from task to task sometimes without taking as much time as I should to leave myself enough breadcrumbs to get back. I'll start working on one thing, and then remember something else, then someone else asks for something, and in the midst of that something else comes up, and before you know it, the day is gone, and I've spent the day working on things that might have been important (or might not) but never made it to my "to do" list. I can't cross them off as 'completed' and I can't remember what I needed to go back to later. Another problem is remembering not only what I did, but how much time I spent on each. Saying that I worked on a given project is one thing, but being able to see that I spent 20 minutes on this project and 2 hours on some other diversion is much more useful. "Have you tried..." I've tried lots of different ways of keeping track of my time before this. I've tried keeping a piece of paper at my desk that I would use to write down everything I did. That worked great... when I remembered to do it. Most of the time, I didn't. I've tried Day One, I even wrote a script that automatically prompted me to write down what I was doing every 15 minutes. But that just meant more interruptions. I tried making it less intrusive (a Growl notification prompting me to make a note in Day One) but that was still a distraction, and I still didn't do it most of the time. I've even tried apps specifically for time tracking, such as the excellent TimeSink. If you're interested in tracking your time and want something that looks nicer and works more easily than my setup, I would suggest trying out TimeSink. You can demo it for two weeks, and there's a 60-day money-back guarantee. Just because I took the nerdy route doesn't mean it's a better way for everyone. I needed a system that was simpler (requiring no effort to use) as well as more precise, giving me the information that I need to be able to recreate my path through the day. Set It and Forget It My solution involves a shell script and Keyboard Maestro which should come as a surprise to exactly no one. There is a way to do it without Keyboard Maestro, but it lacks some of the features. I will explain that more at the end. The basic concept is simple: Every minute, the computer takes a screenshot and saves it to a specific folder with a specific filename. The process is completely automatic and silent, no distractions and nothing to remember. At the end of the day (or anytime during the day), I can look back through the screenshots and piece together my day. After the initial setup, I don't have to do anything to anything to maintain it. By default, the script keep 7 days' worth of screenshots, but you can easily change that. Why I like this setup I find this more helpful than just knowing how long I spent in a particular app because I could have spent 2 hours in Safari doing actual research or I could have spent 5 minutes doing research and the rest of the time chasing rabbits across Wikipedia. I could have spent 30 minutes in BBEdit working on an article, or I could have spent 90 minutes in BBEdit creating a shell script that will save me 10 seconds. And so on. Having a screenshot library of the day also means that I have a chance of remembering things based on vague visual memory. I often myself wishing I could go back and find something that I read online, but can't remember if it was Twitter or Tumblr or RSS or something else. "If I could just see it again I'd remember it." If I was looking at it for more than a minute, I have a screenshot of it. I Once a minute isn't frequent enough to catch everything of course, but it is the digital equivalent of breadcrumbs, and it's a good place to start. I've experimented with shorter and longer times but I keep coming back to one image per minute. I have also added a second script which is triggered whenever an app takes focus, more on that below. Two Options This script was originally designed to work with Keyboard Maestro for the simple reason that it works better in Keyboard Maestro. The script can provide more information coming from Keyboard Maestro, and Keyboard Maestro can also automatically detect when the screensaver is running or when your Mac's display is turned off. That means that Keyboard Maestro can prevent the script from taking a screenshot when all you're going to get is a blank screen.[1] That being said, I realize that some people can't or won't go for Keyboard Maestro, I have added a second option using launchd. (Note that you should only choose one of these options, not both.) Screenshots will be saved to $HOME/Pictures/screenshot-journal/. Inside that folder a new folder will automatically be created for each day. The format for those folders is YYYY-MM-DD which makes it easy to sort them in Finder. Option #1: Keyboard Maestro Setting this up in Keyboard Maestro is simple. (Note: I've only tested this with Keyboard Maestro version 6, but it may work with 5). Download screenshot-journal.sh Save it somewhere in your $PATH such as /usr/local/bin/ Make sure it is executable (chmod 755 screenshot-journal.sh) Download SSJ-Timed.kmmacros and double click the file to import it into Keyboard Maestro. (Optional) Download SSJ-App-Switch.kmmacros and double click the file to import it into Keyboard Maestro. (You can see screenshots on Github if you want to verify they imported correctly.) By default the Keyboard Maestro macro SSJ-Timed.kmmacros is set to run once every minute when you are logged, all day long. You can adjust that in the Keyboard Maestro Editor. You can have it run every "X" minutes or seconds, and you can tell it to only run during certain hours, i.e. maybe you only want to track what you do between 9:00 a.m. and 6:00 p.m.[2] The macro SSJ-App-Switch.kmmacros will run whenever a new app 'activates' (in Keyboard Maestro parlance, aka "takes focus"). This is an optional step which result in more screenshots being taken, but the end result is more complete reconstruction of your day. It's possible that you might switch to an app, write yourself an important note, and then switch back again before SSJ-Timed.kmmacros runs. N.B: If you want to be able to track specific websites such as Facebook, I highly recommend creating Site Specific Browsers using Fluid and then use Choosy to automatically direct clicked links to those browsers. I wrote about this in A better Google search experience with Choosy, Keyboard Maestro and Fluid and Protect yourself from being tracked by Google, Facebook, and others. Filenames when used with Keyboard Maestro When using Keyboard Maestro you will get much more descriptive filenames which will include the name of the current front-most app and the current document title (if any). So, for example, here is one of my most recent entries in today's folder: 15.18.02 [MultiMarkdown Composer] {TUAW.md} timed.gif The first set of numbers is the current time (Mac OS X's filesystem does not like colons in filenames, so I use "." instead.) The [brackets] contain the name of the front-most application and the {braces} contain the name of the front-most window, both of which are recorded by Keyboard Maestro. So, even before I look at the image, I have some idea of what it will show me: it's a screeenshot of when I was writing an article for TUAW using MultiMarkdown Composer. The word 'timed' means that this screenshot was taken by SSJ-Timed.kmmacros. Here is a similar screenshot taken from when I switched to MultiMarkdown Composer from another app 15.37.48 [MultiMarkdown Composer] {TUAW.md} switch.gif You will notice that this filename ends with "switch" (instead of "timed") indicating this screenshot was taken by SSJ-App-Switch.kmmacros. The filenames are designed to be easily sorted in Finder (which will sort them chronologically due to the timestamp as the first part of the filename), as well as easily parsed later on if you want to just find certain apps or certain window names. (Unix note: the whitespace between the fields is one tab followed by one space.) Option #2: launchd If you can't / won't use Keyboard Maestro for some reason, you can use this script from launchd. Download screenshot-journal.sh Save it somewhere in your $PATH such as /usr/local/bin/ Make sure it is executable (chmod 755 screenshot-journal.sh) Download com.tjluoma.screenshot-journal.plist and move it to $HOME/Library/LaunchAgents/ Either restart/logout or load the plist manually using launchctl Those five steps are required. There is one additional optional step: Download beengone, a free program from our very own Brett Terpstra which will tell you how many minutes the user has "been gone" from the computer. If beengone is installed, screenshot-journal.sh will use it to check to see if the computer is idle. (You can even set the number of minutes before the computer is considered idle just by editing one line in screenshot-journal.sh. By default it is 5 minutes.) Using launchd means that you will not be able to add the current app and current window name in the filenames of the screenshots, or take a screenshot whenever you switch apps. For that reason I highly recommend Keyboard Maestro over launchd but I include it as another option. What happens if the computer is idle? If you are using either Keyboard Maestro or beengone (meaning the script can tell if you are idle), you can use imagesnap to get an image captured from the iSight/FaceTime camera on your Mac, if it has one. I added that so I can see if I was on the phone, or talking to someone in my office, or just not in my office, any of which might provide a clue as to what I was doing when I wasn't using the computer. If you don't have imagesnap installed, no image will be captured when the computer is known to be idle. What to do with this information There's no reason to keep track of this information if you're not going to review it. I suggest taking some time at the end of the day to go through the folder of images. A good way to do this is to find today's folder in $HOME/Pictures/screenshot-journal and change to "Cover Flow" (either by pressing ⌘ + 4 or select the "View" menu item and then the "as Cover Flow" option). Then you can use the up and down arrow keys to move through the images, and press the spacebar to take a closer "quick look" view at any particular image. It may also be helpful to group images into folders describing each task, especially if you tend to go back and forth between tasks during the day. Putting all of the images together into one folder will give you an easy way to see how long you spent on a particular task. I was surprised to find that on a day when I thought I had "barely checked email" I had actually spent over 40 minutes in my email client, which might not seem like a lot, but was far more than I would have guessed. I also learned that during the course of one day I worked on about 30 different "projects" but didn't work on any of them for very long. Most of them maxed out at about 20 minutes. But what surprised me the most was that I had switched between tasks so frequently that I was often touching three different "projects" in the span of 20 minutes, or less. But at least there was only one image in the "Facebook" folder (and it would have been zero except I had been "tagged" in an image and wanted to see what it was). I don't plan to go through every day and make those folders, but it seems like a useful thing to do occasionally, especially if I'm having one of those "How did it get to be 8 p.m. already?!" days. Hard drive and CPU usage On my 2.13 GHz Core 2 Duo MacBook Air, I do not even notice when the script runs, even when I had it running every 30 seconds. One day I had about 15 hours worth of images, with a new image every 30 seconds and it took about 160 MB of hard drive space. After reviewing the images, there's no real need to keep them, so you can just trash the entire folder. The script creates GIF images to minimize disk usage. Obviously if you have a retina MacBook Pro, those images will be larger, but again, this isn't intended as long term storage. By default, the script will move old folders to the trash after 7 days. You can change that by editing the line DAYS_TO_KEEP='7' in screenshot-journal.sh. Similarly, by default, images will be stored in "$HOME/Pictures/screenshot-journal/" (with sub-folders created using YYYY-MM-DD). You can change that by editing the line: DIR="$HOME/Pictures/$NAME/" ($NAME refers to the name of the shell script without the path or extension.) While it is pretty easy to check to see if the screen saver is on in a shell script (ps cx | fgrep ' ScreenSaverEngine'), I have not found any way to determine the status of your display(s) from a shell script. So if you have Keyboard Maestro, you will definitely want to use it for this. If you don't have it yet, I encourage you to download the demo and try it for 30 days. ↩ There is one more which is optional, but highly recommended. Download this launchd plist and move it to $HOME/Library/LaunchAgents/. That will ensure that the Keyboard Maestro Engine stays running even if it crashes. If you do this be sure to go into Keyboard Maestro.app's preferences and turn off the option to "Launch Engine at Login" (as shown in the image here), otherwise you will get two copies of the Engine trying to start at the same time, which is bad. ↩

  • 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.

  • Finding Dropbox 'conflicted copy' files automatically

    by 
    TJ Luoma
    TJ Luoma
    02.20.2013

    Dropbox is a great tool, but if you use it on more than one computer, you are bound to find conflicted copies eventually. A conflicted copy is created when the same file is edited on two different computers at the same time, or close enough that Dropbox cannot tell which one is the newest. The good news is that Dropbox creates these conflicted copies instead of trying to guess which file is the one that you want. The bad news is that if you don't notice that Dropbox has created a "conflicted copy, you might start using the wrong file. Unfortunately Dropbox does not alert you when a conflicted copy is created, you have to search for it yourself. Here is an example of a conflicted file: Settings (TJ Luoma's conflicted copy 2013–01–09).textexpander As you can probably guess, the original filename is Settings.textexpander and Dropbox has added the words "conflicted copy" and the date in parentheses, as well as the username. (The username can be helpful if you find a conflict in a shared folder.) Doing it is easy, remembering to do it is hard. I've known that Dropbox creates these files for years, but do I ever remember to look for them? Nope. In fact, I don't even try to remember to look for them. Instead, I have a shell script which does that for me. The shell script runs every five minutes via launchd, and if it finds any conflicts, it alerts me using Growl and growlnotify. It uses a "sticky" notification in Growl, which means that it will not go away until I click on it (but the notification also has a unique ID so only one notification will ever appear on-screen at any given time). Installation Download dropbox-launchd-conflicted-copy.sh to /usr/local/bin/ and make sure it's executable (chmod 755 /usr/local/bin/dropbox-launchd-conflicted-copy.sh). Move com.tjluoma.check-for-dropbox-conflicted-copies.plist to ~/Library/LaunchAgents/ and then either 1) run this line in Terminal: launchctl load ~/Library/LaunchAgents/com.tjluoma.check-for-dropbox-conflicted-copies.plist or 2) log out and back in. How do you find the conflicts once you know that they exist? There are two options that you can use once you are alerted that there are conflicts in your Dropbox. The first is Spotlight, the second is dropbox-launchd-conflicted-copy.sh. Option A) Use Spotlight. Create a search which looks for filenames that match "'s conflicted copy". Actually, you don't even have to make one; you can just download this one DropboxConflicted.savedSearch and move it to ~/Library/Saved Searches/. You might even want to add that to the Finder's sidebar. Note: Once the Saved Search is there, you can even use it with mdfind in Terminal: mdfind -s 'DropboxConflicted' -onlyin "$HOME/Dropbox" Or, if you don't have a saved search, you can use Spotlight on the command line like this: mdfind -name "'s conflicted copy" -onlyin ~/Dropbox Option B) Use find. Call me an old crotchety Unix nerd (pause), but I still prefer the Unix find command instead of Spotlight. Asking Spotlight to look for something is like asking my 10 year old: if he comes back and says that he couldn't find it, I always wonder how hard he really looked. On the other hand: find ~/Dropbox/ -path "*(*'s conflicted copy [0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]*" -print This always gives me reliable results, and it only takes a few seconds. But wait, there's more! The dropbox-launchd-conflicted-copy.sh script is "context aware." When it runs via launchd it gives you the Growl notification shown above, but if it on the command line, it will present you with a list of all of the conflicted files that it found. Just launch Terminal.app, type dropbox-launchd-conflicted-copy.sh and press enter. If you don't have any conflicted files, it will say "No conflicts found" and you can rely on launchd to keep an eye on it in the future.

  • Lingon and launchd can keep crucial apps always running

    by 
    TJ Luoma
    TJ Luoma
    10.30.2012

    Two years ago I wrote about a shell script that I used with cron to keep 'critical' applications running. Some of the commenters suggested that I "should" be using launchd. There are times when I still prefer cron over launchd but there are two reasons why I have started using launchd more often. The first is Lingon, and the second is learning more about what launchd can do. Lingon & the Mac App Store: A Mini-Rant Lingon 3 is a US$3 app which makes writing and managing launchd plists easy. Lingon has been a 'nerd tool' for a long time. A long time ago there was a version available for free. When the Mac App Store opened, Lingon 2 was released for $US5. This naturally enraged some people who believe that software developers have the ability to feed themselves on sandwiches made from air and good feelings. To make matters worse, Lingon ran into the new "sandboxing" restrictions for the Mac App Store. Briefly stated, sandboxing rules now limit what any Mac App Store application can do. These restrictions are imposed by Apple for other developers, even though Apple allows its own software to do many things which aren't possible with sandboxing restrictions. If you have noticed apps leaving the Mac App Store recently, there's a good chance sandboxing is the reason. Sandboxing is a good idea, but right now it is so restrictive that it is causing more problems than it solves. Hopefully this situation will get better as Apple increases what sandboxed apps can do, but for now developers are left with little choice. Peter Borg, Lingon's developer, was faced with a choice: either neuter Lingon 2 to fit sandboxing requirements, or release a new version of Lingon. This was a bit of a "no-win" situation that many developers are facing. Updating Lingon 2 to comply with sandboxing requirements would mean that users who had purchased Lingon 2 and then updated to the newer version would lose features they had paid for. Creating a new version of Lingon would allow the developer to make sure that it complied with sandboxing requirements, but customers who bought Lingon 2 would have to pay for Lingon 3 because the Mac App Store does not have any way for developers to offer upgrade pricing to existing customers. He chose to make a new version of Lingon (version 3) priced at $3 instead of $5, which makes sense because it could do less than Lingon 2. For those who still want Lingon 2, it is still available as a separate app. Despite having made a reasonable choice between two less-than-ideal options, the Mac App Store reviews call it "horrible" and "useless" for not having the features that Apple won't let the developer include. All of which is fairly ridiculous, especially when you realize that you're talking about two versions of an app which, together, cost $8. launchd, KeepAlive, and SuccessfulExit Apple released launchd as part of Mac OS X 10.4 ("Tiger") in 2005, and has steadily improved it ever since. There is no shortage of documentation for it, including Creating Launch Daemons and Agents and the launchd.plist Manual Page, but it's easy to get overwhelmed with the amount of information available. Personally, I find it a lot easier to look at working examples, and see how and why they work. Here's a fairly generic template that I created for you to use: If you want to use that, click/tap on the 'raw' link and it will load in your browser, then save it to your computer. To modify it, just change the two parts written in ALL CAPS. Replace "YOUR.NAME.HERE" with anything you want. It just has to be unique on your system. The "KeepAlive" key tells launchd to restart the process if it stops for any reason. This ensures that the program will be available all the time, but there's a problem: what happens when there's a new version of the app and you want to install the update? You can quit the app, but launchd is just going to restart it. That's where SuccessfulExit comes in. By setting that to 'false' we are telling launchd to only restart this program if the app does not exit successfully. So if you quit the app yourself for some reason, launchd assumes that you want to keep it off until you restart the application, reboot your Mac, or log out and then back in. Then replace "/PATH/TO/PROGRAM/YOU/WANT/TO/KEEP/RUNNING" to the path on your system. Note that if you want to keep an app running, you have to include the path all the way to the executable file, not just the ".app" so if you wanted to keep Dropbox running all the time, the path would be /Applications/Dropbox.app/Contents/MacOS/Dropbox and not just /Applications/Dropbox.app! There are two other potential problems: Spaces in path names Sometimes what you want to keep running isn't obvious at first. I'm going to address both of those using a plist that I use to keep Keyboard Maestro's helper engine running: You'll notice that I don't want to keep Keyboard Maestro running. I want to keep "Keyboard Maestro Engine" running. If you aren't sure what the correct path is, you can go into Terminal.app and type: ps auxww | fgrep -i 'WORD' | fgrep -v fgrep Replace "WORD" with whatever word you want to search for: iTunes, Evernote, Hazel, etc. Look for words such as "Watcher" or "Helper" -- those are often the ones that you might want to keep running. If the path you find has spaces it in (like Keyboard Maestro Engine does), try it without using either quotes or back-slashes () first, and see if it works. If it doesn't work, try adding backslashes before each space or before any punctuation that isn't a period or a slash. Once you have your plist created, save it to ~/Library/LaunchAgents/ and then load it using launchctl load like this: launchctl load ~/Library/LaunchAgents/your.name.here.plist or just log out/reboot. Note: it is a good idea to use the same name for the filename as you chose for the label (YOUR.NAME.HERE) but make sure to add the ".plist" in the filename. Lingon makes it easier Now you know how to plists by hand, but I suspect most people would prefer an easier way. Enter Lingon. Launch Lingon and it will show you all of your existing launchd plists in ~/Library/LaunchAgents/: Don't be surprised if there several already in there. Click the plus (+) at the top-left and Lingon will prompt you to save: Now, I know it might seem counter-intuitive to have "save" be your first step, but you'll see why in a moment. Once you choose a name, Lingon will expand to show you this: Let's take a closer look at that front panel: Lingon has already filled in the "Name" field based on the filename you chose for the "Save As" command. Smart! Now you just have to choose what app or program you want to keep running. I'm going to choose Dropbox. Notice that I have only selected the Dropbox.app itself. "But wait!" you cry, "Didn't you say before that you need to select the app binary, not just the app wrapper?" Yes, I did. But Lingon is smart enough to add the "Contents/MacOS/Dropbox" even though I just selected Dropbox.app. See? Now that you have chosen a program, you need to tell Lingon when you want to run it. Note that I have chosen both "Keep Running" and "At login and at load." Now in my experience, I have not needed to to specify "At login and at load" but the launchd.plist Manual Page says that '[SuccessfulExit] implies that "RunAtLoad" is set to true, since the job needs to run at least once before we can get an exit status.' So I select both. Fortunately launchd is smart enough not to launch two of them. When you're finished, click 'Save & Load' and Lingon will show you your new plist in the list: Voilà! Point and click, with no editing of plist files, no need to drop into Terminal.app, and no need to come back to this page to copy that template that I showed you. Lingon 3 is smart enough to add the SuccessfulExit key and everything else you need. If you use KeepAlive, turn off 'auto-launch' If you do decide to set up a "KeepAlive" for an app such as Dropbox, be sure to go into that app's preferences and turn off the setting to auto-launch the app when you log in. For example, this is Dropbox's preference for that: The reason to turn that off is that otherwise launchd might start the app and it might auto-start on its own, and generally speaking it is not a good idea to run two versions of the same app at the same time. If you decide that you no longer want to use KeepAlive, either go to ~/Library/LaunchAgents and remove the file (and then log out/reboot), or launch Lingon 3, select the plist you want to remove, and select File » Delete Job.

  • 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.

  • Manually schedule Software Update 'the OS X way' with launchd

    by 
    Brett Terpstra
    Brett Terpstra
    01.10.2010

    In response to a Macworld article, TidBits' Chris Pepper elaborated on ways to run Software Update, Apple's means of delivering updates and patches, on your own schedule. Beginning with the fact that Software Update schedules its next update based on the time it's currently being run, setting the time for the next update is as easy as running it manually at the time you want it to be scheduled for in the future. Later, Pepper delves into the command line method of updating, using the softwareupdate tool (which we've talked about on TUAW, too) to run it from Terminal. Taking that a step further, it's suggested that you run the command from cron, a UNIX command for scheduling tasks, to automate the command-line updates. However, while it still works fine and is perfectly capable of the task, cron has technically been deprecated in OS X since Tiger. I thought I'd mention the newfangled "Mac OS X way" of handling scheduled tasks, and demonstrate a little of its flexibility. Launchd is Apple's replacement for several UNIX ways of doing things, including init, rc.d scripts and cron. It provides a uniform, XML configuration method and -- in many cases -- is more secure than the replaced methods. Launchd can trigger applications and scripts at boot time, at intervals or even when a file or the contents of a folder change. It can also make sure a daemon or an application keeps running, with the ability to respawn and throttle it. If that's just a bunch of nerd-speak to you, don't worry, this isn't going to be an overly technical post. You can read more specifics about launchd on Apple's developer site, if you want more geeky goodness.

  • Automatically restart crashed programs

    by 
    Mat Lu
    Mat Lu
    04.24.2007

    Over at Macworld Rob Griffiths has a great column on automatically restarting a program after a crash. Although it is much more stable these days, for a while last year Quicksilver was constantly crashing on me and often I wouldn't notice until ??? + space was strangely unavailing. If there's any program for you, like Quicksilver for me, that simply must be running all the times (but which unexpectedly crashes sometimes), Rob's hint is potentially very handy. It basically involves using Lingon to create a launchd daemon that watches for a crash log and then restarts the application when it sees one. Full instructions are available at Macworld. I'm now going to go see if I can get this set up for Quicksilver.

  • Trigger backups on connect with launchd

    by 
    Michael Rose
    Michael Rose
    12.25.2006

    The fine folks at macresearch.org have put out an interesting tutorial that walks through setting up launchd and rsync to do automatic backups whenever a specific external drive is mounted. Loyal readers may note that this is similar to the core feature of Martian Lifeboat (which should not be confused with Mojave Shade's Lifeboat, as mentioned in several comments). The script, however, is free; Martian Lifeboat is not.Although the currently published script leaves out the crucial -E flag to force rsync to copy resource forks (credit to Josh Wisenbaker of afp548.com for spotting the silent E), it's still a good primer on the power of launchd. For a simple way to create your own launchd configuration files, be sure to check out the powerful, open-source and free Lingon utility. If you try this out, let us know how it works for you.[via macenterprise mailing list]