CrabApple Forest |

Picking The Good Ones & Crabbing About The Bad Ones

Lean on Lingon to launch scripts and applications

Sunday May 11, 2008

Lingon is one of those tools that at first blush may seem to be something only a true geek would love, but it’s actually fairly practical. What it does is to allow you to launch scripts or programs according to certain criteria. If you have previous experience with Linux or Unix, you can think of it as a way to set up something similar to a cron job, except that you have more flexibility.

One thing you can do is set up scripts or applications to launch at startup. Now, you may already know how you can launch applications at startup - you go into System Preferences, click on Accounts, and then (while your account is selected) click on Login Items. Once there, you can add or remove applications you want to launch at startup by using the + and/or - buttons. And, that’s the preferred way to launch an application at startup for the logged-in user.

But what if you want to launch an application based on some other criteria, or you want to launch a script of some kind? What if you need an application to start no matter which user is logging in? Or, what if you want to tweak an existing startup item that’s run by the system (as an agent or a daemon) and not by a particular user? That’s where Lingon comes in. Lingon lets you edit and create configuration files for launchd (and maybe you are asking, what is launchd? Well, according to Wikipedia, “launchd is a unified, open source service management framework for starting, stopping and managing daemons, programs and scripts.” Aren’t you sorry you asked?).

To give you an example of how Lingon can be used, we set it up to start the CallerIDpop perl script from the Michigan Telephone, VoIP and Broadband blog. This is a script used with Linksys/Sipura VoIP adapters (and some phones) that, when there is an incoming call, provides a Growl popup showing caller details and the time the call was received (it can also write this information to a log file). Previously we had been using their suggested method of running an AppleScript (saved as an application) at startup, the AppleScript containing the line that actually starts the Perl script. Although this works, it’s a fairly convoluted way to do it and it seems to eat up a lot of system resources. So, we set out to find another way to invoke the script at startup. Here’s how we did it using Lingon (which, by the way, seems to get the script running a lot quicker, and the script itself seems to be running in a more stable environment):

When you first fire up Lingon, you get this screen:

Lingon opening screen

Click the small button labeled “New” (with the + on the button) in the upper left-hand corner, and you get a dropdown as shown here:

Lingon dropdown

We selected “My Agents” because we only have one user account on that system, and didn’t really want the script to have root privileges. You should think long and hard about running anything as a daemon, because if anything goes wrong (whether due to programming error or malicious intent) the script will be running as root and can do just about anything to your system. Having selected that, we got this window:

Lingon main options window

As you can see, everything is fairly straightforward. In section 1 you give the agent a name, in section 2 you insert the command just as you would enter it if you ran it directly from a terminal window (or you choose the application to run, if you are running an application), and in section 3 you pick the options you want to use to trigger running the script or application. If you’re not sure about any of the options, click on Help (in the top menu bar) and then “Lingon Help” and it will bring up a PDF file in Preview that explains how to use Lingon. The Help menu also gives you access to the man pages for launchd.plist, launchctl, and launchd, in case you are making changes in any of those files.

Note the “Expert Mode” button in the lower right-hand corner - this shows you the actual XML code, and allows you to write keys and values directly if you are comfortable doing that.

Don’t forget to click the “Save” button at the top when you are finished - we forgot to do that and had to start all over! We sort of wish that the “Save” button were underneath the other three sections, maybe in a section 4!

Unfortunately, to make everything work properly you’ll have to log out and login again, or reboot your Mac, as Lingon will remind you:

Lingon restart warning

Not only can Lingon be used to make your own script or application launchers, but it can also be used to edit existing system agents and daemons. While you normally shouldn’t do this, if you know what you are doing it can sometimes improve system performance. On the other hand, if you don’t know what you are doing, you could render your system totally inoperable! As an example of why you might want to do this, we recommend you see the article, “The Case of the Slow Mac (and how to fix it)” at Maciverse. If you think that your Mac is running a bit sluggish, or if you’re seeing the “spinning beachball of death” a bit too often, this article explains one possible reason, and a suggested fix that’s much easier to make if you use Lingon.

Related posts


Customizing the top menubar date and time display

Wednesday May 7, 2008

One of the things that you probably look at a lot more often than you realize is the time display in the top menu bar. If you came from a Windows environment, you may have tweaked out that display to show you the date and/or the day of the week. Apple seems to think it’s sufficient to let you see the time, and if you can figure out how, the (abbreviated) day of the week. We just happen to like having a bit more information available at a glance:

Menubar date time display with dropdown

Above you see our top menubar time display, along with the dropdown menu you get if you right-click on that display. As you see, we show the day of the week (non-abbreviated), the full date (again non-abbreviated), the time complete with seconds, and an AM/PM indication (by the way, it’s only highlighted blue like that because we have the dropdown activated - usually it’s the normal black text on the semi-transparent background). As you may have guessed, we have a wide screen display - were it a regular display we might try to conserve a bit more space, but as it is we have enough screen real estate that we can afford to have the display the way we want it. But, you may be wondering how we did it - if so, that’s the purpose of this article.

To begin with, click on “Open Date & Time” in the dropdown shown above. That will open this preference panel (you might have to click on the “Clock” tab at the top):

Date & Time preference panel - Clock tab

In this panel, check the options shown above and any others you want EXCEPT for “Show the day of the week” - if you check that, you’ll get an ABBREVIATED day (e.g. Mon Tue Wed etc.). We are too OCD around here to want to stare at an abbreviation, we like seeing the word spelled out! While you’re in this panel, click on the “Date & Time” tab and the display will change to this - make sure you have selected a server and that you have checked the box to set date & time automatically.

Date & Time preference panel - Date & Time tab

We would just point out that if you have another machine acting as a timeserver on your local network, or you prefer to use a non-Apple timeserver, you are perfectly free to enter the address into the text field (this example shows using another machine on your local net as a time reference):

Date & Time preference panel - using a local time reference

Anyway, see the button at the bottom of that panel labeled “Open International”? You need to click on that now, which will bring up the International preference pane. Select the “Formats” tab and you will see this display:

International preference panel - Formats tab

First note that the Region is set to “Custom” - we don’t remember doing that, and think that it probably changes automatically once you start customizing formats, but just keep in mind that it probably does need to be set to “Custom” for this to work. Now, note the two “Customize” buttons in the Dates and Times sections. We’ll show you the Times section first, so click on the LOWER “Customize” button, so we can show you how we constructed our date and time string. On the panel that appears, be sure to select “Medium” in the “Show” dropdown, because this is the format the menubar display uses (and just about nothing else uses it, as far as we can see):

Format customization dropdown

Unfortunately our string is a bit longer than the display allows, so in order to let you see it all, here’s the same display but with the cursor moved all the way to the right:

Format customization window - cursor at right

When you first enter this panel, it will show you the current time format, except that if you checked the box to show the (abbreviated) day of the week, that will not appear here. What you want to do is insert the elements you want to use to build your date and time string, as we have done. You can drag any of the elements in the bubbles from the list shown, and you can insert normal punctuation such as commas, colons and spaces. But as you may have noticed, we have “bubble” elements that don’t appear in the panel! Where did we get those? Well, if you back out of this panel to the previous one (”international” panel, “Formats” tab), then click on the FIRST “Customize” button (in the Dates section), and then select “Full” from the dropdown, you should see this panel:

Date customization dropdown

Now, here’s the trick. TEMPORARILY drag the date elements you will need into the text field - you don’t have to remove the ones that are already there, just drop these after the existing string. Then use the mouse, or the shift+arrow keys, to highlight just the elements that you temporarily dragged into the field. Press Command-X to “cut” (copy and delete) those elements, leaving only the original format string (if you make a mistake at any point in this process, pressing Command-Z should undo the last thing you did). Now back out of this panel and click the “Customize” button for the Times section again - once again make sure this dropdown shows “Medium”, then use Command-V to paste the copied date elements into the time string! If they aren’t in the correct order you can highlight each individual item and drag it around until you get it right. Insert any desired punctuation (commas and spaces) and you should be good to go.

It is a little tricky to position the cursor properly during this process (between the “bubbles”), so don’t get too frustrated, just realize that it’s tricky for everyone and you should get it in a few tries, and remember to use Command-Z if you make a mistake.

We do realize that someone will probably want to point out that the latest version of iCal displays the current date on its icon in the dock, but we like to see our date and time information in one place at a glance, not have to search the dock for the iCal icon!

Uber-geek tip: The actual menubar time string format definition is stored in the file ~/Library/Preferences/com.apple.MenuBarClock.plist, and if you knew the correct format you should (theoretically) be able to change it in that file only, with changing the “Medium” time format for other applications. But unless you are a true geek (or like to live on the edge) we don’t recommend attempting to manually edit that file, because you could really mess up your menubar clock. If you simply must try to do it that way, at least please back up the file someplace safe before you start messing with it, so you can restore it if your edits really mess things up!

Related posts


MacFusion: A BETTER GUI for MacFUSE and sshfs

Friday May 2, 2008

We never intended this to turn into a trilogy when we started out, but our quest to find the perfect GUI to set up SSH connections using MacFUSE and sshfs (or, perhaps, as a replacement to sshfs) has turned up yet another candidate. This one may be the best of all, but there’s only one thing about it that gives us pause.

The program is called MacFusion and it’s described as “an open source project released under the Apache License.” (Edit: Although what is supposedly an updated BETA release can be found at macfusionapp.org, we could not get that version to mount a remote filesystem, and it didn’t seem to have as many options in the preferences. Therefore, these instructions are for the original version, which works well for us under Leopard). You can download it freely, but the author does accept donations. It’s more similar to Secure Remote Disk than to sshfs, but it seems to have everything that those other programs are missing. The feature list for MacFusion is as follows:

  • FUSE filesystems so far: SSHFS, CurlFTPFS
  • Passwords can be stored in the keychain for SSH or FTP server
  • Support for public/private key authentication using SSH (Use SSHKeyChain)
  • Stores favorites and allows automatic connection of favorites on start (emphasis added!)
  • Configurable behavior of mounted filesystems on system sleep
  • Handles SFTP:// and FTP:// URL links. Try setting it up with Quicksilver!
  • Sparkle updating

To get it running you simply download it from Google Code and install it as you would any other Mac application (of course, you must have already installed MacFUSE). The first time you start it, it comes up with a rather ominous warning:

MacFusion unvalidated version of MacFUSE warning

We decided to go ahead and try using the program anyway, but obviously we can’t guarantee that you won’t have any problems if you do. However, MacFusion is so much nicer to work with that we’d suggest at least trying it. You can always uninstall it if it doesn’t work properly for you.

MacFusion is a bit different from the other programs we have covered in that it puts an icon in the top menu bar. When you click on that icon, you get a drop-down menu:

MacFusion icon and dropdown menu

There aren’t many preferences but you will probably want to at least check the “Start MacFusion on Login” checkbox (you’ll see why in a moment):

MacFusion Preferences

After you set the preferences, you’ll want to edit favorites:

MacFusion - Favorites - Edit

In the favorites window, click the + at the bottom to add a favorite, then click on SSH to add an SSH connection. Note that with MacFusion you can also connect to an FTP server, something the other programs aren’t designed to do:

MacFusion favorites - add new server

A window will pop up allowing you to add the details of your connection. Note that the name you give in the “Name” field is actually used as the name you see when you move the volume into the Finder left-hand sidebar (unlike Secure Remote Disk).

MacFusion add SSH server

Once you fill in the details and click OK, it will try to connect to the server. Note that you can make more than one connection to the same server. When the server is mounted the button will turn green; while you are still waiting for it to mount it will be yellow:

MacFusion mounting servers

Note that when you are in this panel and you highlight a mounted server, the “Mount” button in the lower right hand corner changes to “Unmount”, so you can mount and unmout your servers at will. But also note the “Auto” checkbox next to each server - if you check that, then when you start up MacFusion it will automatically mount that server. Now keep in mind that in the program’s preferences you can set it to “Start MacFusion on Login”, and now you see that you can have your servers automatically mounted at login or startup.

Unlike Secure Remote Disk, but like sshfs, the pseudo-drives representing your servers are placed in the /Volumes directory, not in subdirectories off your user directory. This is the preferred location. As with sshfs, you can also get to them by clicking on any Finder window, then selecting “Go” in the top menu bar, and then in the dropdown selecting “Computer” (this was all detailed in the first article of this series) . When the Finder window pops up that shows all your drives, you can drag the ones that represent your SSH connections to Finder’s left-hand sidebar (under the devices, not the shared locations), to make them accessible in all Finder windows. The difference with MacFusion is that it will show the name you gave the connection, not the net address of the connected server, so if you give each connection a unique name then that’s what you’ll see in the sidebar.

As before, connections in the Finder sidebar will have an “eject” button next to the name, which if clicked should break the connection to the remote server. But that’s not as important in MacFusion, because you can simply click on its icon in the top menu bar and then use the GUI to mount or unmount connected servers.

And, as we noted above, MacFusion allows FTP servers to be mounted in addition to SSH servers. FTP isn’t as secure as SSH, but in some cases you may have FTP access to a server, but not SSH access. That said, Finder by itself is perfectly capable of making a read-only FTP connection by selecting “Go” in the top menu bar and then “Connect to Server”, but it may be easier to manage FTP connections using MacFusion. We probably wouldn’t install MacFUSE and MacFusion simply to make FTP connections, but if we were already using it to manage SSH connections we’d certainly use it manage our FTP connections as well.

(Edit: Since we first published this article, we came across a post on macosxhints.com that explains how to Mount a gateway-accessed server directly using MacFUSE. You might want to do this if, for some reason (usually involving firewall restrictions) you have to chain a connection through multiple servers. In addition, a comment by a reader of that article mentions that MacFusion can be used to facilitate this. Most users won’t need to do this, but this information is provided for those who do).

In this series of three articles (which was only intended to be a single article at the outset), we have told you about sshfs, Secure Remote Disk, and MacFusion. While all appear to work, MacFusion is in our opinion the hands-down winner in terms of functionality and ease of use. Were it not for that initial warning, which screams out to us that the developer may no longer be interested in keeping this software current with upgrades of MacFUSE, we’d have no problem giving MacFusion our highest recommendation. Despite the warning, MacFusion seems to work with the current version of MacFUSE (as of this writing). And there is some degree of support available through the MacFusion-devel group on Google Groups.

One of our goals in this effort has been to find a no-cost equivalent for a particular commercial program that shall remain nameless in this article, but that also uses MacFUSE at its core. We think maybe it’s a just a bit bit nervy to build your commercial product around someone else’s free software, but we just hope that the company behind the commercial product is compensating the author of MacFUSE in some way. But for those who would rather not purchase that product, we think that for now at least, the combination of MacFusion and MacFUSE gives you most (if not all) of the functionality of that other software. And as we’ve said before, we love free software here in the CrabApple Forest!

Related posts


Secure Remote Disk: A GUI for MacFUSE and sshfs

Thursday May 1, 2008

If you read our earlier article about setting up MacFUSE and sshfs, you may have noted that it’s not exactly intuitive to save your settings, for easy and fast subsequent logins. Also, if for some reason you need to make multiple connections to the same server (for example, to simultaneously be connected under more than one account), that might entail some head-scratching.

Fortunately there are ways to make the connection process easier. In this article we will focus on a program called Secure Remote Disk, which provides a simple GUI for connecting to remote systems. It can be freely downloaded, but the author does ask for donations. You still have to install MacFUSE and (we think) sshfs (but feel free to try it with only MacFUSE installed, if you haven’t yet installed sshfs). You won’t need to use the sshfs application to make your connections. And, as with sshfs, once you have established the connections you can close Secure Remote Disk and the connections will remain in place.

To begin with, download and install Secure Remote Disk in the usual manner. Open the application and you’ll be greeted with a screen similar to this:

Secure Remote Disk

You will see there is already an example connection. “Name” is the name you wish to assign to the connection; it’s not used outside of Secure Remote Disk as far as we can see. We have actually modified the example slightly (as shown above) in order to make a couple of points. First, if you want the server name capitalized, do it for every mention of the server in this panel - otherwise it will appear in lowercase in Finder, which might look a bit strange if you drag the pseudo-drive into Finder’s left-hand sidebar menu (once again, it goes under the devices, not the shared locations), to make it accessible in all Finder windows.

The other, possibly more important point is that you must specify a directory in the lower text entry box - this is a directory on your Mac (not on the remote server), located off of your user directory (which is why it starts with ~/) that will become the link to the pseudo-drive. If you clear this field, you may find that Secure Remote Disk simply hangs, and if you then close and and attempt to re-open it, it crashes on startup. The only way to restore operation is to delete the preferences file for the program (which is found at
~/Library/Preferences/de.prima.jan.SecureRemoteDisk.plist) and start over from scratch. Also, and this is a major difference from the sshfs application, the specified directory cannot be in /Volumes (which is where sshfs normally puts it) - it must be off of your user directory (if you try to put it in /Volumes, it will put it in your user directory anyway!). For most users this will not make any difference, with the caveat that the directory name should not match any existing directory name that you already have, unless that directory was created by Secure Remote Disk (or you) expressly for this purpose. The directory will look like a normal directory when not connected to the server, but you should resist any urge to use it as a normal directory (for storing files, etc.).

Also note that there an Advanced tab:

Secure Remote Disk - Advanced tab

Here you can change the port number for the connection (if the server uses a different port), optionally specify a directory on the remote server (not to be confused with the directory on your Mac that we talked about above), and if you are using a public key rather than a password for access, be sure to check the box shown here.

We didn’t try using password access, but assume that when you attempt to make a connection that requires a password, the program will prompt you for it.

There was one thing about this software that we didn’t like, and we don’t know if it’s a problem with Secure Remote Disk or MacFUSE, or maybe even Finder. We tried making multiple connections to the same server using different user accounts. Although we (obviously) used a different connection name and directory for each connection, when we attempted to drag the connections into Finder’s left-hand sidebar menu, they copied properly but the names shown were that of the server, not the connection name or the directory name. In other words, if you had two connections to Example.com, and dragged them both into the left menu bar in Finder, both would be labeled “Example.com” and the only way to determine which was which would be to open each one and see what’s inside. It would be much better if each were labeled with the connection name, but we don’t know if that’s anything that the author of Secure Remote Disk would be able to do. We think that most users would likely want to have these connections in the Finder sidebar, both for easy access and because doing so provides an eject button next to each connection, which can be used to disable the connection if so desired.

The other thing we wish that Secure Remote Disk offered is the ability to automatically establish some or all connections at startup. As it is now, you have to start it up, click on each connection, then click on the “Connect” button. That’s certainly easier than using sshfs, but it would be nice if there were a checkbox associated with each connection, that if checked would just go ahead and establish the connection whenever Secure Remote Disk is started. Then you could add Secure Remote Disk to the list of programs automatically started at login, and your connections would be established automatically.

The thing that Secure Remote Disk provides is the ability to (relatively) easily make desired connections to your server(s). If you observe the caveat about not trying to leave the Directory field blank on the first screen (the field that specifies the local directory on your Mac), it seems to work very well.

Related posts


See your remote server (almost) as if it were a local drive: Installing MacFUSE and sshfs

Thursday May 1, 2008

Do you own, or have access to a remote server that is accessible via the Internet? Do you know how to, and are you able to make an SSH connection to it using Terminal or iTerm? If the answer to those questions is "yes", then I have another one: How would you like to see files and directories on that system appear in Finder on your Mac, just as if your filespace on that system was an external drive sitting next to your computer? This is not only possible, it’s fairly easy, especially once you get past the initial installation of a couple pieces of software.

The installation is a piece of cake, but it does require a system reboot First go to this page at Google Code and download the correct version of MacFUSE for your operating system, and while you are there you can also download the sshfs package:

Google Code page for MacFUSE

When you have downloaded the MacFUSE package, double click on it and it will mount the disk image. Inside you should see several items, including a package called MacFUSE Core. Double click on it and it will bring up the MacFuse installer.

MacFUSE .pkg icon

Next you will get the opening page of the MacFUSE installer, but first a word from the Apple Nanny:

Apple Nanny

After you dismiss that irritating screen, you can continue with the installation:

MacFUSE Install

Now, at this point we could show you a few more screenshots, but you really don’t need them - on every screen of the MacFUSE installation, all you have to do is click the obvious choice to continue. There are no options to deal with (well, we suppose you could change the default install location, but that’s probably not a good idea).

Unfortunately, in order to actually USE MacFUSE, you then have to reboot your Mac. Yeah, we hate that too. But once you have rebooted, you can then run the sshfs installer (EDIT: Before you do anything with sshfs, see our article on MacFusion: A BETTER GUI for MacFUSE and sshfs - we think you’ll agree it’s a better interface than sshfs. But if you want to install sshfs just to “get your feet wet” with this technology, that’s fine too, and in any case you should continue reading this article for information on ssh authentication, which is also applicable if you use MacFusion). This is just a normal application disk image so click on it to mount it, click on the license agreement, then drag the application icon into your applications folder in the usual manner. Now, when you want to connect to a remote site, just call up the sshfs application and it will prompt you for the information it needs to make the connection:

sshfs connect window

Note that after you have clicked on the "Connect" button, you may or may not be prompted for a password. This will depend on whether you have ever set up public and private keys for authentication without the use of a password on your SSH server. Generally, if you can SSH into the server without entering a password, then sshfs shouldn’t prompt you for a password either.

It’s beyond the scope of this article to explain how to set up ssh public/private key authentication, but there are literally thousands of pages indexed by Google that will tell you how to do it - naturally, some pages give better instructions than others. Try doing a Google search on something like "Mac ssh public key." (If you have found a page of instructions that you feel are particularly helpful, please leave the URL in a comment!)

Note that there are several options that can be used when setting up ssh public key authentication, and everybody that writes up the instructions seems to have an opinion on which options are the best, or generally speaking, the "correct" way to implement this. If only they all agreed with each other! So if you don’t know enough about it to evaluate the information on those pages, you might be better off sticking with using passwords for the time being - except that passwords are not as secure as key authentication, so maybe it would be a good idea to try and set up the key authentication if you can possibly manage it.

Anyway, once you have sshfs going and the connection made, all you have to do is go into Finder and find the icon for your connected share. If you don’t see it, click on any Finder window, then look at the top menu bar and you should see a selection labeled "Go", which when clicked on produces a drop-down menu:

Finder Go menu dropdown

One of the selections is "Computer" - click on that and it should show you a Finder window with all your mounted drives and shares, including (assuming you have successfully connected) the pseudo-drive that represents your ssh connection to the server. Note that you can drag the icon for this drive into Finder’s left-hand menu (under the devices, not the shared locations), to make it accessible in all Finder windows. This will also give you an "eject" button next to the share name, which if clicked should break the connection to the remote server. A possible alternate way to find the pseudo-drive is to look in the /Volumes directory. In either case, it will bear the name of the system you are connecting to.

Note that simply closing the sshfs application does not seem to break the connection to the server, so once the connection is established you can quit the sshfs app and get its icon out of your your dock area. Also, after you have made the first connection to your server, on subsequent connection attempts you should be able to call up sshfs, cancel the connection dialog, and then in the top menu bar click on "File", then "Recent SSH Servers" and select your server for a quicker reconnection.

If you are using a password, then you will still be prompted for it on each connection attempt. As far as we know, there’s no easy way to automatically establish the remote connection as part of the login process. Note that we said "no easy way", not "no way." We’ve found several techniques for doing it, but all involved the use of such things as shell scripts, Applescript, etc. and really seemed a bit overcomplicated to us. We’re thinking there just might be a way to do it in Automator but haven’t had the opportunity to experiment with that yet. If anyone knows of an elegant method for establishing the connection automatically at login (using entirely free software, of course), please let us know in the comments. Otherwise, if we ever figure out a way to do it, we’ll be sure to do a follow-up post explaining the procedure.

There is one known quirk of this software, and that is that it will always report that you have 1000 GB free on the remote system. Apparently this is something that they’ve been unable to work around. Also, bear in mind that this is not commercial software, so there may be a few other things that don’t work quite as you may expect, but on the whole it works remarkably well.

MacFUSE has other uses besides running sshfs. MacFUSE is the Mac implementation of FUSE, which stands for "Filesystem in Userspace." If you want to know more about FUSE, check out the Wikipedia article. One of the other more popular uses of MacFUSE is to allow use of NTFS-3G, a stable read/write driver that allows both read and write access to drives and devices that have been formatted using the Windows NTFS format (be sure to get the version that works with MacFUSE, and please note that we have not tested this so you may want to read up on it prior to installing it, and only use it if you feel it will reliably meet your needs).

Related posts