Running Patch/Standalone in Background

May 11, 2012 at 1:19am

Running Patch/Standalone in Background

I recently was looking through forum posts about this topic, and since there were quite a few threads, I wasn’t sure which one to post on, so I figured I’d start a new one and share what I found.

There are at least three parts to doing this correctly:

1. Create a toplevel patch with the standalone object that will open your actual patch using the ‘shroud ‘ message to pcontrol, and then close itself; such as this one here:

– Pasted Max Patch, click to expand. –

2. When you build your application and collective from the toplevel patch, make sure to include your actual patch and all its dependencies in the build script, because they will not be included automatically.

3. After you have built your application, use the technique found here

http://www.macosxtips.co.uk/index_files/disable-the-dock-icon-for-any-application.php

or use the program that article refrences here

http://foggynoggin.com/dockdodger

to prevent the menu bar and application icon on the dock from showing up.

What results is a program that is invisible to the user (aka does not have a menu bar, does not show up on the dock, does not show up as a process under force quit, and does not have a window). It is also impossible for the anything to end the process outside of a program, so you better have a way to stop it when you want it to. For instance, I am using this method to run max as an audio engine for Unity, and here is the C# code I use to start the program and end it (using System.Diagnostics and System.IO from the .Net library, included with Unity).

using UnityEngine;
using System.Diagnostics;
using System.IO;

public class OpenFile : MonoBehaviour {

FileInfo info = new FileInfo(“/Users/JohnCassidy/Documents/MaxPatches/BGPatchOpenerApp.app/Contents/MacOS/BGPatchOpenerApp”);
Process maxPatch;

// Opens standalone when Unity app starts
void Start () {

maxPatch = Process.Start(info.FullName);

}

// Closes standalone when Unity app stops
void OnApplicationQuit () {

if (!maxPatch.HasExited) {

maxPatch.CloseMainWindow();

}
}
}

It is important that the file path points to the executable, otherwise the app will not close properly.

For windows, all you would have to do is find some Windows specific way to accomplish step 3 (hiding the app from the taskbar), and make appropriate changes to the file path in your program.

If you really want to go one step further, and not even have a visible loading screen for your patch, you can use the techniques referenced in this forum post:

http://cycling74.com/forums/topic.php?id=28967

and the included example patch (uploaded as an attachment to preserve patcher inspector properties)

I hope this helps anyone interested in this topic.

Cheers!

-John Cassidy

#63544
May 11, 2012 at 2:26am

Apologies about that unity code. Let me see if this works better.

using UnityEngine;
using System.Diagnostics;
using System.IO;

public class OpenFile : MonoBehaviour {

	FileInfo info = new FileInfo("/Users/JohnCassidy/Documents/MaxPatches/BGPatchOpenerApp.app/Contents/MacOS/BGPatchOpenerApp");
	Process maxPatch;

	// Opens standalone when Unity app starts
	void Start () {

		maxPatch = Process.Start(info.FullName);

	}

	// Closes standalone when Unity app stops
	void OnApplicationQuit () {

		if (!maxPatch.HasExited) {

			maxPatch.CloseMainWindow();

		}
	}
}
#229074

You must be logged in to reply to this topic.