0

I have a simple command line app

#include <unistd.h>

int main(int argc, const char* argv[]) {
  sleep(100);
  return 0;
}

Is it possible to make that command line app show an icon in the dock while it's running or do I have to turn it into a full on app package?

gman
  • 100,619
  • 31
  • 269
  • 393
  • It is possible, WINE does this (although it might require a GUI window, not sure). For a typical command line app, this sounds strange. Why would you want to do this? – Alexander O'Mara Nov 20 '14 at 22:48
  • Because my command line app creates a modal dialog. But that dialog can appear behind other windows and the user has no way to find it except to close/move/minimize all other windows. Adding an icon to the doc means they have a way to find the dialog. – gman Nov 20 '14 at 22:54
  • @AlexanderO'Mara, the Mac driver of Wine chooses to not transform the background process to a foreground app until the Windows program shows a window, but that's not required by the frameworks. – Ken Thomases Nov 21 '14 at 03:02

1 Answers1

1

Given that the app creates a modal dialog, I assume it's using Cocoa. In that case, you can do [[NSApplication sharedApplication] setActivationPolicy:NSApplicationActivationPolicyRegular] at the point where you display the dialog.

You should be aware that the Dock may show an odd icon. Prior to Yosemite, unbundled executables got a generic icon that looks a bit like a terminal window with the word "exec" in it. The title would be the name of the executable. In Yosemite, the Dock icon for an unbundled executable will be the icon of the folder/directory containing the executable. Its title will be that folder's name, too. (As far as I'm concerned, this is a terrible decision on Apple's part but what are you going to do?)

Ken Thomases
  • 88,520
  • 7
  • 116
  • 154
  • Thanks. Actually that seems like a pretty good decision. It let's you choose an icon relatively easily. Ideally I'd like to be able to choose an icon in 10.9- as well. I tried setting `sharedApplication.applicationIconImg` but no luck :( – gman Nov 21 '14 at 03:57
  • Not sure how to do this in XCode but I can do a GetInfo in the finder on the command line app's file and paste in an icon. That icons shows up in the doc. Not sure how to automate that process in XCode. – gman Nov 21 '14 at 05:17