No internet connection
  1. Home
  2. How to

Split text taken from UI Element

By Alex Oldroyd @Alex_Oldroyd8
    2022-01-18 23:46:10.565Z

    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

    • 22 replies

    There are 22 replies. Estimated reading time: 8 minutes

    1. 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.

      1. AAlex Oldroyd @Alex_Oldroyd8
          2022-01-18 23:52:16.542Z

          Just testing with log atm - but the aim is to use it to save a patch

          1. In reply toKitch:
            AAlex Oldroyd @Alex_Oldroyd8
              2022-01-18 23:52:58.650Z
              
              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);
              
              1. AAlex Oldroyd @Alex_Oldroyd8
                  2022-01-19 00:05:52.205Z

                  yes it does! :). Thanks again, Kitch!

                  1. Kitch Membery @Kitch2022-01-19 00:11:30.067Z

                    @Alex_Oldroyd8... Also see the following posts;

                    They will come in handy for sure!

                  2. In reply toKitch:
                    AAlex Oldroyd @Alex_Oldroyd8
                      2022-01-19 00:15:13.161Z

                      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
                      });
                      
                      1. AAlex Oldroyd @Alex_Oldroyd8
                          2022-01-19 00:26:06.266Z

                          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
                          });```
                          1. Kitch Membery @Kitch2022-01-19 00:27:32.825Z

                            That works too!!! Great stuff.

                            1. 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.

                              1. AAlex Oldroyd @Alex_Oldroyd8
                                  2022-01-19 00:38:32.831Z

                                  Ah yes you're right. Only works for first 2 tracks...

                                  1. In reply toKitch:
                                    AAlex Oldroyd @Alex_Oldroyd8
                                      2022-01-19 00:39:15.661Z

                                      Is there a better way to 'get' track name? Thanks

                                      1. Kitch Membery @Kitch2022-01-19 00:41:28.642Z

                                        Yep... Bump this thread on the weekend also and I'll show you how.

                                        1. AAlex Oldroyd @Alex_Oldroyd8
                                            2022-01-19 00:45:31.484Z

                                            :) 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}`);
                                      
                                      1. AAlex Oldroyd @Alex_Oldroyd8
                                          2022-01-19 00:42:24.796Z

                                          This seems to work for all tracks now, Kitch!! Thank you again! :)

                                          1. 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.

                                            1. AAlex Oldroyd @Alex_Oldroyd8
                                                2022-01-19 01:55:09.282Z

                                                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!

                                                1. Kitch Membery @Kitch2022-01-19 02:14:37.056Z

                                                  Share what you have so far and I'll take a look when I can :-)

                                                2. In reply toKitch:
                                                  AAlex Oldroyd @Alex_Oldroyd8
                                                    2022-01-19 02:01:48.553Z

                                                    Hey Kitch. I can't work out what trackHeaders is? Could you post the variable definition too please?

                                                    1. Kitch Membery @Kitch2022-01-19 03:53:45.723Z

                                                      Oops, Updated above.

                                                      1. AAlex Oldroyd @Alex_Oldroyd8
                                                          2022-01-19 08:44:57.475Z

                                                          Thank you!