Is there a way to get Max to launch another application?

Andy Maskell's icon

I want to get Max to load three other apps that my patcher interfaces to (Mixing-Station, X-Edit and CuBase) after my patcher executable has loaded. Sounds simple but I have yet to find out how.

Thanks.

tyler mazaika's icon

The [shell] external should work as a starting point for this. Then you just need to know the Unix (Mac) or Power Shell (Windows) commands to send to [shell]. You can look in the forums for references to shell, or just look here: https://github.com/jeremybernstein/shell/releases/tag/1.0b3

Andy Maskell's icon

It turns out that you can do it really easily by using a ;max launchbrowser message but you'd never work that out from reading the documentation!

Note: The full application path needs to be enclosed in quotes if it contains spaces and each backslash needs to be doubled up as it's a special character in Max.

Source Audio's icon

or maxlaunchbrowser

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

can launch files, apps

davidestevens's icon

@sourceaudio - thanks for that. I’ve spent ages batting my head against that one, and the bit I was missing was an understanding of how to use conformpath.
By the way - [shell] doesn’t work in arm64/mac mode on an M1.

tyler mazaika's icon

re: [shell] I had no problems on M1 (native) once I pulled the build from the GitHub url above.

davidestevens's icon

Yup, you’re right - I just checked again. Is there somewhere that there’s a good listing of useful-in-max commands for shell? I don’t find the helpfile particularly helpful, and everything i’ve found when googling commands is either too limited, or too complex for me.

Andy Maskell's icon

I messaged the support team about using “;max launchbrowesr” and they said it was only ever intended for opening a browser URL or html file. Any ability to execute an application will come down to the quirks of your individual OS and default browser combination, which is why they decided not to include it in the documentation. I did suggest that they might want to look at adding an official way to do this but they seemed to prefer us to share our own solutions!

Source Audio's icon

https://ss64.com/

lists most Mac-Win commands and is a good start when looking for shell commands.
Different to terminal on mac or command prompt on windows,
one has to fight with max specific quotas, backslashes, etc,
otherwise most of that stuff simply works.
shell needs slash based paths.
even osascript works (mac only), for example
osascript -e 'tell application \"TextEdit\" to activate make new document at the front' -e 'tell application \"System Events\" to keystroke \"Hi there ! \" '

For executable binaries not included in standard OS locations,
one has to provide absolute path, for example :
~/Documents/FFMPG-332/ffmpeg -h
in case ffmpeg executable is in user Documents/FFMPEG-332/ folder
Also for any files - use absolute paths.
even if files you want to use are in Max search path,
does not mean that shell - binary that needs to find them looks there.
If I wanted to merge 2 stereo files into 1 quad using ffmpeg :
~/Documents/FFMPG-332/ffmpeg -i ~/Desktop/Audio/inA.wav -i ~/Desktop/Audio/inB.wav -filter_complex "amerge=inputs=2,channelmap=0|1|2|3:channel_layout=quad" -c:a pcm_s16le ~/Desktop/Audio/outAB.wav

All absolute paths, otherwise it won't work.
*** by the way ~/ is usable on both Mac and Win as user directory.

Using sudo on Mac which needs password is another case,
can be executed using penter 'password' or including password into command.

On windows I use little app elevate.exe to execute commands
as admin from max, or another option is to bundle bat or cmd scripts into small
exe files with admin execution flag set and execute them using
;
max launchbrowser file:/....
or shell open

... enough for today ...

davidestevens's icon

Thanks @source audio, that’s really helpful.

enki's icon

This works on my Mac OS, Max 8. In a message type. (If your folders or files have spaces in their name then you'll have to rename them- Message doesn't like spaces)

;max launchbrowser "file:///Users/enki/Documents/ARQuestion.rtf"

Source Audio's icon

At least my max version 8 removes quotas if there is no space in the string.
if you paste this into message:
;max launchbrowser "file:///Users/enki/Documents/ARQuestion.rtf"
you will end with:
;max launchbrowser file:///Users/enki/Documents/ARQuestion.rtf

if it was:
;max launchbrowser "file:///Users/enki/Documents/AR Question.rtf"
then quotas will remain and file will launch.