View Full Version : Badge icons and Terminal
Mar 12, 2012, 09:09 PM
I currently have an Applescript app that opens Terminal windows and completes commands. Is there anyway to have a badge icon appear on the Terminal icon when a command completes?
Mar 13, 2012, 12:12 AM
I don't think you can access another application's dock tile (not easily anyway). What OS are you running? If you can use AppleScriptObjC, a badge can be added to your own application's dock tile easily enough.
Mar 13, 2012, 12:44 AM
I have definitely had my terminal display badge icons, but it wasnt immediately obvious to me how it was done. My guess would be it based on the exit code of the utility. I bet with some google Kung foo you could make this happen.
Mar 13, 2012, 02:49 AM
I'm running OS X 10.6.8. Never heard of AppleScriptObjC before. Any ideas how it could be used in this situation?
Mar 13, 2012, 02:50 PM
AppleScriptObjC is a framework introduced in Snow Leopard 10.6 that lets you write Cocoa applications using AppleScript - it is the successor to the deprecated AppleScript Studio. In addition to Xcode, there are a couple of ways you can use ASObjC in a regular script - Lion's AppleScript Editor includes a Cocoa-AppleScript application template, and the background application ASObjC Runner (http://www.macosxautomation.com/applescript/apps/runner.html). Both will run in Snow Leopard, although you will need a copy of the template from Lion to use that (the Cocoa-AppleScript template will need to be used in this case, since the application is referenced when getting the dock tile).
What exactly are you trying to do? Provide something like a progress bar?
Mar 13, 2012, 03:59 PM
Nope, essentially my Applescript application takes a user inputted variable and plugs it into a Terminal command. Everytime I use the application it opens a new Terminal window (intended). I would like to have a badge icon appear when a Terminal command completes.
Mar 13, 2012, 05:01 PM
I created a simple Cocoa-AppleScript example that sets and clears a badge on its dock tile, to see if that is what you are looking for. You can download it here (http://www.users.qwest.net/~red_menace/Files/Forum%20Stuff/Cocoa-AppleScript%20Applet.zip) - the main script is located in the application bundle's Contents/Resources/Scripts folder.
Mar 13, 2012, 07:12 PM
Alright, I have to admit I'm not a coder which is why I used Applescript since its so easy and logical. All the Applescript app does is open a Terminal window with the command and then it quits itself. I want the badge icon on the Terminal window not the Applescript app. Is that possible?
Mar 13, 2012, 07:56 PM
I'm running OS X 10.6.8.
I don't think I've ever seen Terminal badging in 10.6.*. Or anything earlier, either. And I use Terminal a lot. In fact, it's an Open At Login item and sits in the middle of my Dock, and has been since 10.0.
Google search terms: mac os terminal badge
The top two results:
In fact, those seem to be the only really relevant results at all.
Those posts to StackExchange clearly explain what causes Terminal badging (bell characters in output), on what OS version (Lion), and even give an example of how to produce it (sleep 3; printf '\a') on the relevant version of Terminal.
I see nothing at all about badging in Terminal on any other OS version. So off-hand, I'm going to guess "Not possible", but I'm perfectly willing to admit I lacked sufficient google-fu to produce the answer.
Badging isn't something you can do from another process. The process with the badge has to support badging itself. If it doesn't support badging, you can't make it show a badge. To put that in terms of Terminal, only Terminal.app supports badging (or not, before Lion). The processes you run in Terminal.app, like bash or sleep or printf, can only produce output on the pseudo-tty that Terminal itself interprets as a trigger to badge itself. This is a direct consequence of Terminal's support for badging, not something directly caused by those other processes. So without Terminal's ability to recognize bell characters and badge itself, no other process can tell Terminal to badge itself. It would require an in-process extension to do that (security issues), or trickery with Dock.app.
Mar 13, 2012, 08:17 PM
All the Applescript app does is open a Terminal window with the command and then it quits itself. I want the badge icon on the Terminal window not the Applescript app. Is that possible?
My application just puts a badge on its own dock tile, with a couple of dialogs to pause long enough to see the result (you can see the script by looking in the application bundle or by dragging the application onto the Script Editor). I am guessing that this is for feedback or status - is there a reason for wanting this particular kind of feedback?
As mentioned, I don't think there is a handy way to put a badge on another application's dock tile. I've looked around a bit and found Docktopus (http://startly.com/products/docktopus/1/), so it looks like it can be done (in a fashion), although I'm not sure of the level of UI scripting or hackery required.
Mar 13, 2012, 08:30 PM
Well since I often have a lot of Terminal windows open its hard to know when a command ends. So it'd be nice to have a badge icon with the number of completed Terminal windows for convenience.
Mar 13, 2012, 08:34 PM
Does your application keep track of what has been completed (closes windows, etc), or are you trying to get Terminal to do all that and just let you know somehow?
Mar 13, 2012, 08:48 PM
Nah, all it does is take the username inputted, plug it in to the command, open Terminal, and then it quits. So I'm looking for the latter.