Control mouse click with Python

857 viewsCSS Questionspython
0

Hi Remotify forum members,

I see that Remotify has a user.py script that can run methods (a python class), can I run python code here that I currently run in terminal?

I have a python script (that I run manually) that listen for a specific midi command (sent from a midi controller when a button is pressed), when this command is received it clicks the ‘Type’ area (see attached picture) in Ableton’s browser to activate it so that I can copy in clip packs from a folder to tracks (Deck A and B). I do this as I have no other way of Activating Ableton’s browser.

I’m a bit of a new beginner in scripting and with Ableton so I would like to know if it is possible before I spend to much time on it, is this something that can be done with Remotify and python?

These are my imports in my python script;

import argparse
import os
import signal
import sys
import time
import rtmidi
from pynput.mouse import Button, Controller as MouseController
from pynput.keyboard import Key, Controller as KeyboardController

Joachim Answered question January 27, 2025
0

I’m guessing you can use any module that’s part of the Python’s Standard Library without a problem.

I don’t have a clue how you would be able to use 3rd party modules though. If you right-click on the Ableton app, access its contents and navigate to “/Applications/Ableton Live 11 Suite.app/Contents/App-Resources/Python/site-packages”, then you might be able to manually install a python module here???

Am I understanding you correct that you only click “type” so that the Browser would come into focus?
If so, then maybe the “Focus View” Action is what you need (Live Object Models > Application > Focus View):

Otherwise, you could maybe let your external script run in the background and have it be triggered by specific messages in a log. You could then make Reactions that writes those messages to the log.

Glenn Verhaeghe Answered question January 5, 2025
0

Hi Glenn,

thanks for answering!

Yes you are correct, I only click on ‘Type’ in order to bring Live’s Browser into focus.

From what I understand the Max 4 Life’s LOM (The Live Object Model) is more or les the same as the undocumented Control Surface Scripts Model (maybe I can figure out how to use “Focus View”  as you suggested in my Control Surface Scripts).

When I have the browser in focus I use ‘down’, ‘up’, ‘right’ keys (my current python script catches Midi commands from my controller and sends these navigation keys) to select files (a clip pack). I then use Command + C to copy and then I send key ‘1’ or ‘2’ (tracks one and two are key mapped to 1 and 2) to select tracks in Ableton Live’s session view where I send Command + V to past the clips.

As I’m a beginner with Ableton Live and scripting in general I would be happy if you could give me some more pointers or maybe even some code examples (if you happen to have some).

Edit

I played around with Remotify and I now see where the picture you include comes from.

Dose this mean that Max 4 Life’s LOM (reversed engineered pyton version of it) is available from within Remotify?

Joachim Edited answer January 6, 2025
0

Yes, M4L’s LOM is as good as the same as the LOM in the Ableton Live API that CSS uses.

On this site you can find an overview of the API (its functions and classes etc.)

Through the Reactions Mapping, you can build all sorts of stuff using either the GUI that’s provided by CSS or by using custom code. I’ve compiled a spreadsheet to make it easier to look for the different options (using the search or using filters). I’d suggest saving a copy to your account.

Some examples

In this post I made a Reaction for someone, using custom code, to navigate through Tracks while folding and unfolding Group Tracks.

In this post someone asked for Reactions that could make the volume fade in or out.

For this post I made a Reaction that links knobs to track names.

Other interesting topics

Here’s a post to a problem that might pop up when you make your own Reactions: if a Reaction is triggered by a change in Ableton’s UI, then the Reaction itself can’t immediately trigger another change in the UI; it needs to be delayed. You can achieve this delay with a function. It’s useful to keep it in mind, if it ever arises.

In this post I explained how you can create delayed actions with python’s threading module; i.e. an action that plays out after some time or an action that plays out after you held a button for some amount of time.

Glenn Verhaeghe Answered question January 7, 2025
0

Thanks Glenn,

Much appreciated I will take a thorough look at it all!

Joachim Answered question January 7, 2025
0

Hi Glenn,

I have looked at Control Surface Studio and I can achieve simple things with Reactions in CSS, e.g. I can select the Browser in Ableton (I get the black border around the Browser) when I press a button on the midi controller and I can navigate up and down between the folders when I have first manually selected the top level/folder (‘Good DJ set’) with the mouse (having focus on Browser is not enough in order to navigate with keys up, down and right).

My understanding of the API is very limited but I can’t see how and if this can be done.

I’ll describe what I would like to be able to do and what I have achieve with python;

  1. Click on ‘Type’ in the Browser area to select it
  2. Navigate down (up and down) by sending key ‘up’ and ‘down’ and I dive into a folder by sending key ‘right’
  3. when I have the right song selected (a clip pack, the .als file) I copy it by sending Command + C
  4. Send key ‘1’ (track 1 is key mapped to 1) to select track 1 and paste by sending Command + V

Do you think that this can be done with a Control Surface script? If yes I would appreciate a few pointers if you have the time.

Joachim

Edit, added my simple attempt of a script

Joachim Unselected an answer January 11, 2025