Split text taken from UI Element
Hi all. After capturing text from a UI Element using the technique in @Kitch 's video, would it be possible to only take the text up until first hyphen?
In Logic Pro X, at the top of the main window it states the Project Title, Alternative Title and the Window Name all separated by a hyphen. In order to 'get' the Project Title, is there a way to remove all text after the first hyphen?
Thanks
Alex

- Kitch Membery @Kitch2022-01-18 23:48:32.206Z
What's the code you have so far?
Once I have that, I can show you after that how to remove the text after the hyphen.
- AAlex Oldroyd @Alex_Oldroyd8
Just testing with log atm - but the aim is to use it to save a patch
- In reply toKitch⬆:AAlex Oldroyd @Alex_Oldroyd8
var trackName = sf.ui.app("com.apple.logic10").mainWindow.groups.whoseDescription.is("Inspector").first.children.whoseRole.is("AXList").first.groups.allItems[2].textFields.first.value.invalidate().value; var projectName = sf.ui.app("com.apple.logic10").mainWindow.getElement("AXTitleUIElement").value.invalidate().value; log(trackName projectName)
- In reply toAlex_Oldroyd8⬆:Kitch Membery @Kitch2022-01-19 00:00:25.726Z
This will get the Project Name.
const projectName = sf.ui.app("com.apple.logic10").mainWindow.getElement("AXTitleUIElement").value.invalidate().value.split(" - ")[0]; log(projectName);
- AAlex Oldroyd @Alex_Oldroyd8
yes it does! :). Thanks again, Kitch!
Kitch Membery @Kitch2022-01-19 00:11:30.067Z
@Alex_Oldroyd8... Also see the following posts;
They will come in handy for sure!
- In reply toKitch⬆:AAlex Oldroyd @Alex_Oldroyd8
Ok one more - now to finish this script, I'd like to enter text value into text area trackName projectName
const trackName = sf.ui.app("com.apple.logic10").mainWindow.groups.whoseDescription.is("Inspector").first.children.whoseRole.is("AXList").first.groups.allItems[2].textFields.first.value.invalidate().value; const projectName = sf.ui.app("com.apple.logic10").mainWindow.getElement("AXTitleUIElement").value.invalidate().value.split(" - ")[0]; sf.ui.app("com.apple.logic10").windows.whoseTitle.is("Save Patch as…").first.textFields.first.elementSetTextAreaValue({ value: projectName trackName });
- AAlex Oldroyd @Alex_Oldroyd8
Whoop!! Worked it out! :)
const trackName = sf.ui.app("com.apple.logic10").mainWindow.groups.whoseDescription.is("Inspector").first.children.whoseRole.is("AXList").first.groups.allItems[2].textFields.first.value.invalidate().value; const projectName = sf.ui.app("com.apple.logic10").mainWindow.getElement("AXTitleUIElement").value.invalidate().value.split(" - ")[0]; const patchName = (trackName+" "+projectName) sf.ui.app("com.apple.logic10").windows.whoseTitle.is("Save Patch as…").first.textFields.first.elementSetTextAreaValue({ value: patchName });```
Kitch Membery @Kitch2022-01-19 00:27:32.825Z
That works too!!! Great stuff.
- In reply toAlex_Oldroyd8⬆:
Kitch Membery @Kitch2022-01-19 00:31:54.509Z
I fear that the way you are getting the track name may only work for track you you originally had selected (Possibly the 2th or 3rd track in the Logic arrange window). Let me know if that's the case and maybe we can revisit it when I have some spare time.
- AAlex Oldroyd @Alex_Oldroyd8
Ah yes you're right. Only works for first 2 tracks...
- In reply toKitch⬆:AAlex Oldroyd @Alex_Oldroyd8
Is there a better way to 'get' track name? Thanks
Kitch Membery @Kitch2022-01-19 00:41:28.642Z
Yep... Bump this thread on the weekend also and I'll show you how.
- AAlex Oldroyd @Alex_Oldroyd8
:) Gonna be a wild weekend! ha
- In reply toAlex_Oldroyd8⬆:
Kitch Membery @Kitch2022-01-19 00:26:56.894Z
You can do this by using template literals
const trackName = sf.ui.app("com.apple.logic10").mainWindow.groups.whoseDescription.is("Inspector").first.children.whoseRole.is("AXList").first.groups.allItems[2].textFields.first.value.invalidate().value; const projectName = sf.ui.app("com.apple.logic10").mainWindow.getElement("AXTitleUIElement").value.invalidate().value.split(" - ")[0]; sf.ui.app("com.apple.logic10").windows.whoseTitle.is("Save Patch as…").first.textFields.first.elementSetTextAreaValue({ value: `${projectName} ${trackName}` });
You can see what the result is if you log like this;
log(`${projectName} ${trackName}`);
- AAlex Oldroyd @Alex_Oldroyd8
This seems to work for all tracks now, Kitch!! Thank you again! :)
Kitch Membery @Kitch2022-01-19 00:58:46.569Z2022-01-19 03:53:29.378Z
No need to wait for the weekend for this on... Here is the code you need to get the selected track name;
const logic = sf.ui.app('com.apple.logic10'); const trackArea = logic.mainWindow.groups.whoseDescription.is('Tracks').first.groups.whoseDescription.is('Tracks'); const trackHeaders = trackArea.allItems[1].splitGroups.first.splitGroups.allItems[1].scrollAreas.first.groups.whoseDescription.is('Tracks header').first; // Get Selected Track Name const selectedTrackName = trackHeaders.getElements('AXSelectedChildren').first.getString("AXDescription").match(/“(.*)”/)[1]
Updated.
- AAlex Oldroyd @Alex_Oldroyd8
You're a hero! Thank you. I've put it all together in a new post. Very proud of the script but unfortunately it's falling at the last hurdle!
Kitch Membery @Kitch2022-01-19 02:14:37.056Z
Share what you have so far and I'll take a look when I can :-)
- In reply toKitch⬆:AAlex Oldroyd @Alex_Oldroyd8
Hey Kitch. I can't work out what trackHeaders is? Could you post the variable definition too please?
Kitch Membery @Kitch2022-01-19 03:53:45.723Z
Oops, Updated above.
- AAlex Oldroyd @Alex_Oldroyd8
Thank you!