Max for Live JavaScript code to delete inactive devices on the selected track

Adrien Dousse's icon

Hello everyone,

I'm trying to make a simple device, that has one button, that when pressed will delete all inactive devices on the selected track. The thing is, I know next to nothing about js and m4l for that matter. I do know a bit of programming generally speaking, and so I've tried with chatgpt to quickly come up with the js script.
According to the latest debugging iteration, chatgpt says:
"Unfortunately, Max for Live's LiveAPI object provides access to properties and some methods but does not directly support device deletion. This limitation is inherent in the API and not something the script itself can override."

Can someone confirm ?
I actually have m4l device, "session cleaner" that does that for the entire project. So i'm sure its possible somehow



Rivanni's icon

Devices cannot delete themselves. You need to go to the track that houses them.

Tracks has a function called delete_device.

Sonoran Music Devices's icon

Here is how I have a device self delete. I just had to make this yesterday. The chain object has a delete_device function.

// This device is live_set tracks 0 devices 0 chains 0    
var api = new LiveAPI("live_set");    
api.goto("live_set tracks 0 devices 0 chains 0");
api.call("delete_device", "0");

Adrien Dousse's icon

Thank you all, got it working !
having a hard time to implement code so that undo is possible within live !!
there must be a straightforward way to do this ?