No internet connection
  1. Home
  2. How to

I want to change the icon in Finder

By Yujiro Yonetsu @Yujiro_Yonetsu
    2020-11-09 12:07:38.521Z2020-11-09 13:07:55.222Z

    Hello

    I want to change the icon in the Finder.
    I have several colored icons available.
    I want to color the session data icons for better visibility of the data I'm working on.

    Here's an example of a place where I have an icon

    The contents of this folder are empty and exist only for the icons.

    Here's my script as it stands now.
    It works fine, but I feel it's too redundant.
    Is there any way to make it more concise?

    This script is for a red folder.

    
    sf.ui.finder.menuClick({
        menuPath: ["File","Get Info"],
    });
    
    sf.keyboard.press({
        keys: "cmd+shift+g",
    });
    
    sf.wait({
        intervalMs: 50,
    });
    
    
    sf.keyboard.press({
        keys: "slash",
    });
    
    sf.ui.finder.mainWindow.sheets.first.comboBoxes.first.elementSetTextFieldWithAreaValue({
        value: "~/Desktop/icon/",
    });
    
    sf.ui.finder.mainWindow.sheets.first.getElement('AXDefaultButton').elementClick();
    
    sf.wait({
        intervalMs: 50,
    });
    
    sf.keyboard.press({
        keys: "f",
    });
    
    sf.wait({
        intervalMs: 50,
    });
    
    
    sf.ui.finder.menuClick({
        menuPath: ["File","Get Info"],
    });
    
    sf.keyboard.press({
        keys: "tab",
    });
    
    sf.ui.finder.menuClick({
        menuPath: ["Edit","Copy"],
    });
    
    sf.wait({
        intervalMs: 50,
    });
    
    
    sf.ui.finder.menuClick({
        menuPath: ["File","Close Window"],
    });
    
    sf.wait({
        intervalMs: 500,
    });
    
    
    sf.ui.finder.menuClick({
        menuPath: ["Window","Cycle Through Windows"],
    });
    
    sf.wait({
        intervalMs: 50,
    });
    
    
    sf.keyboard.press({
        keys: "tab",
    });
    
    sf.ui.finder.menuClick({
        menuPath: ["Edit","Paste"],
    });
    
    sf.wait({
        intervalMs: 50,
    });
    
    sf.ui.finder.menuClick({
        menuPath: ["File","Close Window"],
    });
    
    Solved in post #4, click to view
    • 4 replies
    1. Kitch Membery @Kitch2020-11-10 10:37:31.097Z2020-11-10 10:46:53.424Z

      Hi @Yujiro_Yonetsu,

      Something like this should do it;

      const iconFolderPath = 'Desktop/Icons/Final Mix';
      
      const destinationFolderPath = 'Desktop/Destination';
      
      
      function copyIcon(iconFolderPath) {
          sf.system.exec({ commandLine: `open -R "${iconFolderPath}"`, });
      
          sf.ui.finder.menuClick({ menuPath: ["File", "Get Info"], });
      
          sf.ui.finder.windows.whoseTitle.endsWith('Info').first.elementWaitFor();
      
          sf.keyboard.press({ keys: "tab", });
      
          sf.wait({ intervalMs: 200 });
      
          sf.ui.finder.menuClick({ menuPath: ["Edit", "Copy"], });
      
          sf.ui.finder.menuClick({ menuPath: ["File", "Close Window"], });
      
          sf.ui.finder.windows.whoseTitle.endsWith('Icon').first.elementWaitFor({ waitType: 'Disappear' });
      }
      
      function pasteIcon(destinationFolder) {
          sf.system.exec({ commandLine: `open -R "${destinationFolder}"`, });
      
          sf.ui.finder.menuClick({ menuPath: ["File", "Get Info"], });
      
          sf.ui.finder.windows.whoseTitle.endsWith('Info').first.elementWaitFor();
      
          sf.keyboard.press({ keys: "tab", });
      
          sf.wait({ intervalMs: 200 });
      
          sf.ui.finder.menuClick({ menuPath: ["Edit", "Paste"], });
      
          sf.ui.finder.menuClick({ menuPath: ["File", "Close Window"], });
      
          sf.ui.finder.windows.whoseTitle.endsWith('Icon').first.elementWaitFor({ waitType: 'Disappear' });
      }
      
      function main() {
          sf.ui.finder.appActivate();
      
          sf.ui.finder.appWaitForActive();
      
          copyIcon(iconFolderPath);
      
          sf.wait({ intervalMs: 300 });
      
          pasteIcon(destinationFolderPath);
      }
      
      main();
      

      Just change the iconFolderPath & destinationFolderPath :-)

      1. Yujiro Yonetsu @Yujiro_Yonetsu
          2020-11-10 13:44:54.309Z

          Thank you for your advice.
          I feel like I'm definitely getting closer to my hopes.

          But as far as the destination folder is concerned, I'd like to specify the file that is always selected.
          What changes should be made to achieve this?
          Please.

          1. Kitch Membery @Kitch2020-11-10 19:41:50.885Z

            Just change the "Destination Folder Path" to this

            const destinationFolderPath = sf.ui.finder.firstSelectedPath;

            ReplySolution
            1. Yujiro Yonetsu @Yujiro_Yonetsu
                2020-11-10 20:38:20.522Z

                Thank you!