Executing a shell script from Max.... how?

warp1's icon

I'm trying to run a shell script from within Max using the 'Shell' object. My process is currently to simply cd into the folder and 'run' the script, but that doesn't seem to do anything. I can run single commands using shell so the object is working fine. Can anyone point me in the right direction?

shellscript.maxpat
Max Patch

testcase's icon

if you turn on the stderr attribute of the shell object you might see what is wrong. could it be a permission problem?

Source Audio's icon

no need to cd, just send script path to shell.
use slash based path

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



warp1's icon

Thank you! That seems to work in terms of at least trying to execute the shell script. However I have another issue. I am basically trying to run a shell script on an Android device (for which I am using the adb platform tools). I have set the path to the platform tools folder just fine, and I can ping the device via Max to show it is connected, but when I run this script i get 'adb: command not found'. The command being used in the script is HAS_DEVICE=$(adb devices| grep device). When I run the same slash based script in the terminal it runs just fine, no errors. Any ideas what might be going on?

adb_version.maxpat
Max Patch

Source Audio's icon

difficult to trace without the package and script,
but I guess that it is same issue as with script itself.
You are telling shell object to execute something, and it cant find the command.
Maybe add full path to adb executable in the script ?

Source Audio's icon

or place script next to executable, same path ...

warp1's icon

I'm on a Mac, so not sure about executable. I just have the platform tools folder with the adb commands in there. I have placed the script in this folder, but not sure if that is what I should be doing. As I said, this script runs just fine if I run it from Terminal directly. Just not sure about Max.

Source Audio's icon

Did you try adding abs path in the script ?
And why don't you try talking directly to shell.
Another option if all you want is that script to execute,
try

;
max launchbrowser file:///...

warp1's icon

Basically I think the problem is that Max does not seem to have a way of identifying or loading the path variables that a particular user has. In terminal when you open a shell these paths (such as the path to the adb platform tools) are loaded by default. In Max there does not appear to be an option to do that, which means the script needs to be modified to be specific to that user (inserting the path). The problem is that I do not want to have everyone I am sending the shell script to have to modify that line in the script. This is the whole reason I am using Max, to create a simple GUI that does not involve modifying scripts, and can just run them.

Source Audio's icon

Paths in max can be automated, set etc.
I know nothing about your project, so it is difficult to make suggestions.

warp1's icon

I understand, and thank you for your help so far! I cannot share the script unfortunately, but it does appear that this is an OS-level / user directory issue that I have a knowledge gap on. I will just have to keep digging.

warp1's icon

@source Audio I am wondering about this command that you mention. The command 'works', but it only opens the script - it doesn't run it. Is there a way to make it execute?

; max launchbrowser file:///...

Source Audio's icon

To execute script it should be saved as command and given executable rights.
It would then run in terminal.
script saved as plain text with extension command,
like make-folder.command
to make it executable from terminal:
chmod +x path to the command

You can also run it from shell in max
just send it path to the command.

Source Audio's icon

Maybe you'll be better off making applescript or platypus app or something.
Do you need any interaction with the script ?
If not, I am sure you can do all from shell in max

warp1's icon

I am still obviously missing something. Here I've attached the patch I'm trying to get working, and included the portion of shell script that is throwing an error as below:

HAS_DEVICE=$(adb devices| grep device)
if [ -z "$HAS_DEVICE" ]; then

printf "No device connected. Terminating."

exit 2;

fi

if [ "$1" = "--device" ]; then

shift

DEVSTR="-s "$1

shift

fi

I would be wanting to create a standalone application (hence the standalone object in there), so I was thinking I could bundle the platform tools and use a relative search path, but that does not seem to work.

Max_ADB.maxpat
Max Patch

Source Audio's icon

Are you sure that it would be possible to bundle platform tools and shell
into standalone and sign and notarize it ?
In any case I would use absolute path to standalone.
Just to test it I downloaded that tools
and sending a message :
~/Downloads/platform-tools/adb devices
or
~/Downloads/platform-tools/adb version | grep Installed

works allright, but I have no devices to check the rest
~/ is shortcut to user folder