No internet connection
  1. Home
  2. How to

Making a mouse click happen

By Will Reynolds @Will_Reynolds
    2019-10-21 17:04:02.276Z2019-10-21 17:12:28.721Z

    Hi there,

    I am trying to make a logic preset selector - i have gotten to the point where i have made an instrument track, opened the library, then gotten the mouse to hover over the search field but I can't seem to get it to click on the position of where the mouse is. I've attached the code below.

    var logic = sf.ui.app('com.apple.logic10');
    logic.menuClick({
        menuPath: [ 'Track', 'New Software Instrument Track' ]
    });
    
    sf.keyboard.press({
        keys: 'y'
         });
    
    sf.mouse.setPosition({
        position: {"x":40,"y":400},
    });
    
    sf.mouse.click({
         position: {"x":40,"y":400},
        clickCount: 1,
    });
    
    • 5 replies
    1. Wow @Will_Reynolds
      That's impressive progress with Logic given that we have so little existing support for it.
      I'll take a look.

      1. Which version of Logic are you using?
        In my 10.3.3 "New Software Instrument Track" just adds a track without any popup window.
        How does the popup window look like in your version?

        1. In mine I have to press the "New Tracks..." menu item, then I can do like this:

          
          var logic = sf.ui.app('com.apple.logic10');
          logic.menuClick({
              menuPath: ['Track', 'New Tracks…']
          });
          
          //Wait for the New Track sheet to appear
          var sheet = logic.mainWindow.sheets.whoseDescription.is('New Track').first;
          sheet.elementWaitFor();
          
          //Choose Software Instrument
          sheet.radioGroups.first.radioButtons.whoseTitle.is('Software Instrument').first.elementWaitFor();
          
          //Choose Retro Synth -> Stereo
          sheet.groups.whoseDescription.is('Details').first.groups.first.popupButtons.first.popupMenuSelect({
              menuPath: ["Retro Synth", "Stereo"],
          });
          
          //Click Create
          sheet.buttons.whoseTitle.is('Create').first.elementClick();
          
          //Wait for Sheet to close
          sheet.elementWaitFor({ waitForNoElement: true });
          
          1. WWill Reynolds @Will_Reynolds
              2019-10-22 08:35:51.678Z2019-10-22 10:52:07.394Z

              Hey Christian,

              Thanks for that! I managed to figure a way and I'll attach the code below - unfortunately because it isnt a menu name i had to use mouse clicks . Thank you so much!

              var logic = sf.ui.app('com.apple.logic10');
              logic.menuClick({
                  menuPath: [ 'Track', 'New Software Instrument Track' ]
              });
              
              sf.keyboard.press({
                  keys: 'y'
                   });
              
              sf.mouse.setPosition({
                  position: {"x":40,"y":400},
              });
              
              sf.wait({
                  intervalMs: 400,
              });
              
              
              sf.mouse.click({
                  position: {"x":40,"y":400},
                  clickCount: 1,
              });
              
                   sf.wait({
                  intervalMs: 500,
              });
              
              sf.keyboard.type({ text: 'COOL PAD' });
              
                   sf.wait({
                  intervalMs: 200,
              });
              
              sf.mouse.setPosition({
                  position: {"x":40,"y":450},
              });
              
              sf.wait({
                  intervalMs: 200,
              });
              sf.mouse.click({
                  position: {"x":40,"y":450},
                  clickCount: 1,
              });
              
              sf.keyboard.press({
                  keys: 'y'
                   });
              
              1. Hi Will.

                Happy that you got this working for you.
                Can you show me this in some screenshots?

                The reason I'm asking is that you are using the mouse and keyboard simulation functions, where I think it should be possible to do stuff more directly.
                We always try to avoid keyboard and mouse simulation, since it is less stable.

                In your code above, you are essentially using absolute coordinates. So if you moved the Logic window, this would stop working.

                Logic fortunately has a great integration with our UI automation layer, so you really should be using that instead.

                To get further into how to use this, I would encourage you to start with the macro editor, and to use actions like:

                • Click UI Element
                • Wait for UI Element
                • Mouse Click Relative to UI Element

                If you want to convert this to Javascript, you can click the three small dots on each action.

                But it's a great way to start making more stable macros/scripts.