1. Welcome to the new MacRumors forums. See our announcement and read our FAQ

Badge icons and Terminal

Discussion in 'Mac Programming' started by greenythebeast, Mar 12, 2012.

  1. macrumors regular

    #1
    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?
     
  2. macrumors 6502

    #2
    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.
     
  3. macrumors 6502

    seepel

    #3
    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.
     
  4. macrumors regular

    #4
    I'm running OS X 10.6.8. Never heard of AppleScriptObjC before. Any ideas how it could be used in this situation?
     
  5. macrumors 6502

    #5
    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. 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?
     
  6. macrumors regular

    #6
    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.
     
  7. macrumors 6502

    #7
    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 - the main script is located in the application bundle's Contents/Resources/Scripts folder.
     
  8. macrumors regular

    #8
    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?
     
  9. macrumors 603

    #9
    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/ques...unts-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.
     
  10. macrumors 6502

    #10
    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, 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.
     
  11. macrumors regular

    #11
    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.
     
  12. macrumors 6502

    #12
    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?
     
  13. macrumors regular

    #13
    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.
     

Share This Page