No internet connection
  1. Home
  2. Support

Script not always getting current text from clipboard

By Zach Moody @Zach_Moody
    2022-02-18 18:58:11.202Z

    Title

    What do you expect to happen when you run the script/macro?

    I based this script off of @raphaelsepulveda excellent Copy a pre-existing folder in Finder to the current folder location script.

    This script should first run a script in Filemaker that copies a projects information into the clipboard.

    Then it copies a Templete folder into the selected folder in the Finder and renames it with the text from the clipboard.

    Are you seeing an error?

    What happens when you run this script?

    After running the scipt if you change to a different project in Filemaker and run the script again it doesn't put the new project's information in the folder name but the original project's information. You have to run the script twice after changing the project in FIlemaker to get the new project information in the folder name. The Filemaker script is copying the new project information into the clipboard each time you run the script, but the information isn't getting updated in the Soundflow script.

    How were you running this script?

    I used a keyboard shortcut within the target app

    How important is this issue to you?

    4

    Details

    {
        "inputExpected": "I based this script off of @raphaelsepulveda excellent Copy a pre-existing folder in Finder to the current folder location script.\n\nThis script should first run a script in Filemaker that copies a projects information into the clipboard.\n\nThen it copies a Templete folder into the selected folder in the Finder and renames it with the text from the clipboard.",
        "inputIsError": false,
        "inputWhatHappens": "After running the scipt if you change to a different project in Filemaker and run the script again it doesn't put the new project's information in the folder name but the original project's information. You have to run the script twice after changing the project in FIlemaker to get the new project information in the folder name. The Filemaker script is copying the new project information into the clipboard each time you run the script, but the information isn't getting updated in the Soundflow script.",
        "inputHowRun": {
            "key": "-Mpfwh4RkPLb2LPwjePT",
            "title": "I used a keyboard shortcut within the target app"
        },
        "inputImportance": 4
    }

    Source

    
    function copyTemplateToSelectedFolder() {
        // Insert the template folder's path here
        const templateFolderPath = '/Users/zachmoody/Box/CLIENTS/TEMPLATE';
        //const templateFolderName = templateFolderPath.split('/').slice(-1)[0];
        const templateFolderName = sf.clipboard.getText().text;
        // Get path of selected directory
        const selectedPath = sf.ui.finder.firstSelectedPath;
    
        // Copy
        sf.file.copy({
            sourcePath: templateFolderPath,
            destinationPath: `${selectedPath}/${templateFolderName}`
        });
    
        log('Template copied!')
    };
    
    sf.ui.app('com.filemaker.client.pro12').menuClick({
        menuPath: ["Scripts", "Copy Title for Folder Naming"],
    });
    
    copyTemplateToSelectedFolder();
    
    

    Links

    User UID: PK7MrNcgoyUfepXBHxbD9Uvnheh2

    Feedback Key: sffeedback:PK7MrNcgoyUfepXBHxbD9Uvnheh2:-MwDBiJ6t5Fw0OmqmHX_

    Feedback ZIP

    Solved in post #2, click to view
    • 4 replies
    1. Kitch Membery @Kitch2022-02-18 19:29:11.530Z

      Hi @Zach_Moody,

      What you are seeing may be caused by how quickly SoundFlow is executing its commands.

      To rule this out you may need to first clear the clipboard, then wait for it to be loaded with text,

      Here is an example of what I mean.

      //Clear the contents of the clipboard.
      sf.clipboard.clear();
      
      //Add text to the Clipboard.
      sf.clipboard.setText({text:"Text you want to store in the clipboard"});
      
      //Wait for Clipboard to be populated with text.
      sf.clipboard.waitForText();
      
      //Log the Text stored in the clipboard.
      log(sf.clipboard.getText().text);
      

      So in this scenario;

      function copyTemplateToSelectedFolder() {
          // Insert the template folder's path here
          const templateFolderPath = '/Users/zachmoody/Box/CLIENTS/TEMPLATE';
          //const templateFolderName = templateFolderPath.split('/').slice(-1)[0];
          const templateFolderName = sf.clipboard.getText().text;
          // Get path of selected directory
          const selectedPath = sf.ui.finder.firstSelectedPath;
      
          // Copy
          sf.file.copy({
              sourcePath: templateFolderPath,
              destinationPath: `${selectedPath}/${templateFolderName}`
          });
      
          log('Template copied!')
      };
      
      
      //Clear the contents of the clipboard.
      sf.clipboard.clear();
      
      //Populate the Clipboard with text
      sf.ui.app('com.filemaker.client.pro12').menuClick({
          menuPath: ["Scripts", "Copy Title for Folder Naming"],
      });
      
      //Wait for Clipboard to be populated with text.
      sf.clipboard.waitForText();
      
      copyTemplateToSelectedFolder();
      
      

      This is untested, as I don't have FileMaker pro but give it a shot and see if it works :-)

      Reply1 LikeSolution
      1. Z
        In reply toZach_Moody:
        Zach Moody @Zach_Moody
          2022-02-18 19:40:51.425Z

          Thanks Kitch, that works perfectly!
          I was close. I tried sf.clipboard.clear but didn't think SoundFlow might be going to fast. You're awesome.

          1. Kitch Membery @Kitch2022-02-18 20:02:59.315Z

            Awesome!

            Glad it's working now :-)

            Side Note, if you did not know already... whenever you are using a "method" for example .clear, .getText or .setText , be sure to add parenthesis after the method otherwise the method ie .clear(), .getText() or .setText(), otherwise the methods will not run.

            Rock on!

            1. ZZach Moody @Zach_Moody
                2022-02-22 03:17:01.709Z

                Thanks Kitch,
                I've got a lot to learn but it's exciting when it works. Thanks for the help.