Making a mouse click happen
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,
});
- Christian Scheuer @chrscheuer2019-10-21 17:12:55.653Z
Wow @Will_Reynolds
That's impressive progress with Logic given that we have so little existing support for it.
I'll take a look.Christian Scheuer @chrscheuer2019-10-21 17:15:47.903Z
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?Christian Scheuer @chrscheuer2019-10-21 17:26:01.248Z
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 });
- WWill Reynolds @Will_Reynolds
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' });
Christian Scheuer @chrscheuer2019-10-22 10:51:59.949Z
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.