1

I have two Unity3D applications - one launched by the other, with a -batchmode argument on the launched one so it has no graphics.

On Mac OSX the launched process still gets a dock icon that sits there bouncing forever; clicking it does nothing since it's non-graphical, and I'd really like to remove it.

I've tried modifying the Info.plist with a LSUIElement entry to get rid of the dock icon. That works perfectly if I launch the application myself, but it still gets a dock icon when I launch it as a process.

My process launching code is a little unusual which mightn't be helping. This works on Windows and Linux but not OSX and I'm not sure why (C#, mono):

ProcessStartInfo proc = new ProcessStartInfo();
proc.FileName = path + filename;
proc.WorkingDirectory = path;
proc.Arguments = commandlineFlags;
process = Process.Start(proc);

I've only got it to launch on OSX with this specific setup:

ProcessStartInfo startInfo = new ProcessStartInfo("open", "-a '" + path + filename + "' -n --args " + commandlineFlags);
startInfo.UseShellExecute = false;
process = Process.Start(startInfo);
Nition
  • 43
  • 5

2 Answers2

1

You will need MonoMac for this if you are not already using it, either the older open-source version or the commercial version (Xamarin.Mac).

In the Unity app that you are launching as a 'sub-process' from the first app add a project reference to MonoMac and add a using clause for MonoMac:

using MonoMac;

Then in your static Main function:

MonoMac.AppKit.NSApplication.Init ();
MonoMac.AppKit.NSApplication.SharedApplication.ActivationPolicy = MonoMac.AppKit.NSApplicationActivationPolicy.Accessory;

That will hide the application/process from dock and task switcher... Of course you can conditional skip that code if you are running on Windows/Linux.

SushiHangover
  • 73,120
  • 10
  • 106
  • 165
  • Thanks Robert. Unfortunately Unity's version on Mono is relatively ancient and doesn't seem to like MonoMac, as least as far as I could get with it. Luckily I actually managed to get rid of the doc icon with a couple of extra parameters in ProcessStartInfo (see my answer). – Nition Oct 01 '15 at 00:55
1

Answering my own question, but adding these to the ProcessStartInfo removed the dock icon:

startInfo.CreateNoWindow = true;
startInfo.WindowStyle = ProcessWindowStyle.Hidden;

I'm not sure if both of those is actually needed, but there doesn't seem to be any harm.

A PList edit seems to be needed as well. Specifically I'm adding:

<key>LSBackgroundOnly</key>
<string>1</string>

As found here.

Community
  • 1
  • 1
Nition
  • 43
  • 5