/ OS X

CUPSLauncher OS X

CUPS is the standards-based, open source printing system developed by Apple Inc. for OS X® and other UNIX®-like operating systems. CUPS uses the Internet Printing Protocol (IPP) to support printing to local and network printers.

CUPS stands for “Common Unix Printing System” and on OS X it usually does its job behind the scene, without much interaction with the enduser.

<code class="language-bash ">     cupsctl WebInterface=Yes
     open http://localhost:631/

Now you can bookmark the link in your browser. As long as the WebInterface of cupsctl is not reset to its default value “No”, there is no need to run the command on terminal again.

Cupslauncher View all completed jobs

As I often forget the necessary commands and the needed localhost port number I wrote the small app (and this blog post). On top of that, it was a good opportunity to play again a bit with xcode and Swift.

For those interested in the underlying Swift Code, please find it right here:

// // AppDelegate.swift // CUPSLauncher // // Created by Jeannot Muller on 26/03/15. // Copyright (c) 2015 Jeannot Muller. All rights reserved. // import Cocoa @NSApplicationMain class AppDelegate: NSObject, NSApplicationDelegate { @IBOutlet weak var window: NSWindow! func applicationDidFinishLaunching(aNotification: NSNotification) { // Insert code here to initialize your application NSAppleScript(source: "do shell script "cupsctl WebInterface=Yes"" )!.executeAndReturnError(nil) NSAppleScript(source: "do shell script "open http://localhost:631/jobs?which_jobs=completed"" )!.executeAndReturnError(nil) exit(0) } func applicationWillTerminate(aNotification: NSNotification) { }}

Of course this code is a bit quick and dirty. As you can see, I haven’t implemented any error-handling if one of the operation wouldn’t work (for instance CUPS not installed, or no browser available). The hard exit(0) is not ideal either, but for the purpose of this small program it’s exactly all what we need, the “App” should not even show up at all but kill itself and all resources after having launched the CUPS front end in the default browser.

Feel free to re-use the code and to optimize the application, as long as you please share your thoughts and ideas with me.