No internet connection
  1. Home
  2. How to

How to change colors of Finder Tags?

By Stephan Vester @Stephan_Vester
    2022-01-25 14:13:26.152Z2022-01-25 18:52:16.941Z

    Desired Workflow

    The macro should do a menu item click "Ablage->Tags ..." and from there I would go on choose a color...

    Question

    Hi everyone,
    I wanted to create a simple macro to create and change colors of Finder Tags since I often change colors of files depending on the state of the mix-session for example.
    I'm able to click "Ablage" but when I want to click "Ablage->Tags ..." I always get a "cant find menu item".
    I tried a million ways to spell it. Didn't help. It works with other menu item clicks though. Then I thought to trie it another way by only click item "Ablage" and then do a mouse absolute position click to the colors shown in the menu...wich works as long as the menu stays the same in height:) Wich of course changes for example depending on if you have one or multiple tabs open. So, not an option.. Any suggestions? It cant be that hard..
    I saw someone had a PT-Finder-Color Package in the shop, but I`m not able to download it.
    Best
    Stephan

    Command Info

    ID: user:ckya9uwbu0003y210p87ohzov:ckyu6kp8a0001qa10a074lmgu
    Name: Finder Tag Blue
    

    Source

    
    sf.ui.finder.menuClick({
        menuPath: ["Ablage","Tags ..."],
        looseMatch: false,
        targetValue: "Toggle",
        forceClick: false,
    });
    
    
    

    Links

    User UID: FkWDGiXolNSwiDxmwVrCwXWH7dz2

    Feedback Key: sffeedback:FkWDGiXolNSwiDxmwVrCwXWH7dz2:-MuG_O6edx7COBk5pzLh

    Feedback ZIP

    • 10 replies
    1. Hi Stephan,

      macOS probably uses the single-character ellipsis character for the three dots, so not "...", but "…".

      1. SStephan Vester @Stephan_Vester
          2022-01-26 11:52:54.064Z

          Hi Christian,

          thanks for your answer!!
          I didnt know about this single-character ellipsis. Learned something:)

          You are right...for every other menu click in the finder with "…". (For example "Darstellung" "Symbolleiste anpassen …"
          But unfortunately it doesn`t work for "Ablage" "Tags …" Weird!
          What is different to that menu button?
          Any idea!

          Best
          Stephan

          1. SStephan Vester @Stephan_Vester
              2022-01-26 11:53:01.866Z

              ?

              1. Hi Stephan,

                I did some digging and it looks like macOS hides the "Tags..." label from that specific menu item. And even if I invoke the menu item directly, it doesn't react like it would if you click it manually :/

                1. I got this pretty hacky thing semi-working here - maybe it'll work for you as well

                  
                  sf.ui.finder.getMenuItem('File').elementClick();
                  sf.wait({ intervalMs: 200 });
                  
                  var tagsButton = sf.ui.finder.getMenuItem('File').children.first.children.allItems.find(c => c.children.first.fullRole === 'AXRadioGroup');
                  var tagsButtonFrame = tagsButton.frame;
                  
                  var oldPos = sf.mouse.getPosition().position;
                  
                  try {
                  
                      sf.mouse.setPosition({
                          position: {
                              x: tagsButtonFrame.x + 15,
                              y: tagsButtonFrame.y + 34,
                          },
                      });
                  
                      sf.mouse.click({
                          position: {
                              x: tagsButtonFrame.x + 15,
                              y: tagsButtonFrame.y + 34,
                          },
                      });
                  
                      sf.wait({ intervalMs: 500 });
                  
                  } finally {
                  
                      sf.mouse.setPosition({
                          position: oldPos,
                      });
                  
                  }
                  
                  1. SStephan Vester @Stephan_Vester
                      2022-01-26 12:40:01.621Z

                      Oh wow,
                      Fast!

                      thanks again!
                      I just copied and pasted it...
                      I dont understand every bit of the code since I´m still with macros:) But it seems you did kind of the same what I tried before by automating a mouseclick. (Right?).. Wich doesnt always work because the menu changes depending on how many tabs you have open for example..

                      Cheers
                      Stephan

                      1. Yes it uses a mouse click but it bases where it clicks on where the Tags field is located so it should work :)

                        1. samuel henriques @samuel_henriques
                            2022-01-26 15:37:04.390Z

                            Not sure if I it helps, I use this apple script.

                            /**
                            * @param {'unset'|'orange'|'red'|'yellow'|'blue'|'purple'|'green'|'grey'} color
                            */
                            function setColorAppleScript(color) {
                                sf.system.execAppleScript({
                                    script:
                                        `
                            property unset : 0
                            property orange : 1
                            property red : 2
                            property yellow : 3
                            property blue : 4
                            property purple : 5
                            property green : 6
                            property grey : 7
                            
                            tell application "Finder"
                                   repeat with f in selection as alias list
                                           set label index of f to ${color}
                                   end repeat
                            end tell
                            `
                                });
                            }
                            
                            
                            setColorAppleScript("orange")
                            
                            1. Nice!

                              1. SStephan Vester @Stephan_Vester
                                  2022-01-27 21:00:25.849Z

                                  Hey Christian,
                                  yes of course it works. Sorry, maybe I didnt select a file at one point yesterday..:) Not sure why it didnt always work. Now it does!

                                  And also thanks Samuel!

                                  Do you guys see any way of toggling the color?:) For example a file is marked as red and I want to change it to green.
                                  The best scenario for me would be to have the colors on the deck and then be able to toggle the colors as I would with the mouse.

                                  Cheers
                                  Stephan