PDA

View Full Version : Badge icons and Terminal




greenythebeast
Mar 12, 2012, 08: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?



Red Menace
Mar 12, 2012, 11:12 PM
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.

seepel
Mar 12, 2012, 11:44 PM
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.

greenythebeast
Mar 13, 2012, 01: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?

Red Menace
Mar 13, 2012, 01: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?

greenythebeast
Mar 13, 2012, 02: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.

Red Menace
Mar 13, 2012, 04: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.

greenythebeast
Mar 13, 2012, 06: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?

chown33
Mar 13, 2012, 06: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:
http://apple.stackexchange.com/questions/23191/terminal-doesnt-show-badge-how-to-enable
http://apple.stackexchange.com/questions/18605/is-there-a-way-to-suppress-badge-counts-and-the-dock-icon-bounce-for-terminal-ap

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.

Red Menace
Mar 13, 2012, 07: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.

greenythebeast
Mar 13, 2012, 07: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.

Red Menace
Mar 13, 2012, 07: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?

greenythebeast
Mar 13, 2012, 07: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.