Is external application already running? And bring its window to front!

Andy Maskell's icon

I know I've seen something about this before but I'm blowed if I can find from a search!

How can I test to see if another application I need to interface to is already running? I'm using Windows 10 and I need to find out if CuBase is already running or not when I launch my project.

Ideally, I'd also like to bring it's window into the forground.

Any ideas would be welcome!

11OLSEN's icon

Max Patch
Copy patch and select New From Clipboard in Max.

the external is on my page.

Andy Maskell's icon

Thank you. It would be perfect I suspect but I'm running Windows and your external is only compiled for Mac.

11OLSEN's icon

nope. mxe64 is the Win external (64bit)

Andy Maskell's icon

I must be looking in the wrong place then as the zip that I've downloaded only has the Mac version.

11OLSEN's icon

Ok. You went here? Zip seem to be complete.

Andy Maskell's icon

Yes,I've got a download with the mxe64 in now. So where do I put it? Haha!

Andy Maskell's icon

I've put the folder in my Documents/Max 8/Packages folder and the Package Manager lists it as installed but when I load your patch the Console says the 11globalForegroundWindow object is unknown!

11OLSEN's icon

Create a folder where you put all 3rd party externals. Add that folder to Max searchpath (Options->File Preferences).
Or save externals in a Folder which is in the searchpatch by default. for example: C:/Users/<name>/Documents/Max 8/Library/

Andy Maskell's icon

Cracked it! Brilliant! Thank you so much.

Andy Maskell's icon

Just to let you know that I've used your 11globalForegroundWindow with an error trap as you suggested and it works absolutely brilliantly with Cubase and Mixing-Station, the two apps that I'm interfacing to. I can now switch between apps as I change the data feed for my console and my project now automatically clears the memory recall store and reloads the apps if they have been closed and/or crashed. Totally brilliant solution for my needs! Thank you.

For clarity, the connector colours are:
White: initialisation routine (from loadbang)
Bright red: data switching routine
Dark red: Cubase
Green: Mixing-Station
Black: error handling
Red objects: links to the memory bank for each app configuration

11OLSEN's icon

I'm glad that it's useful. I think i will add a message to the object to check if an app is running. Seems more elegant than catching the error. Also error messages are not equal on Win and Mac versions. it's on my todo list.

Andy Maskell's icon

Thank you. I'd be happy to test it for you if you do although I'm only Windows based, as much as I'd prefer to be running a Mac!!! I've credited you for use of the routine in my patch. Do you have an "official" copyright notice and a donations page?

11OLSEN's icon

I added a message "isrunning <appname>" to do the check.
I have my tag in the console. No donations page atm but nice of you to ask ;)

Andy Maskell's icon

Ok. I'll try the new version and report back. The tag in the console is what I had used to credit you thus far.

Andy Maskell's icon

Hey! Yes, it works! I'll have to rework my logic a bit to use the isrunning message though.

11OLSEN's icon

There's nothing wrong with the error catching way but it's good to have a separat message to do the check without setting the focus.

Andy Maskell's icon

The only problem with the error method is that it will be triggered by any error, albeit with the ability to filter out the ones that matter. I’ve rewritten my patch to use the isrunning method and it works a treat:

Thank you.

fabio m's icon

Hello, sorry to resume this old thread...

I would like to get the same behaviour but with NOT bringing the newly launched (or already running) app: any help?

As I'm using TouchOSC to control Ableton from a tablet, I would need to be sure that both TouchOSC Bridge and OSC Keypress are running or, if not, they are launched but stay in the background.

Thank you.