No internet connection
  1. Home
  2. How to

How to run a section of a script in the background

By Andrew Sherman @Andrew_Sherman
    2021-10-19 10:28:08.676Z

    I know how to run a system process in the background, using shell script or AppleScript.

    sf.system.exec({
                commandLine: `
                Shell script goes here
                `,
                executionMode: 'Background',
            });
    

    And I also know how to combine separate background processes:

    sf.system.exec({
                commandLine: `
                Process 1 &
                Process 2 &
                wait
                `,
                executionMode: 'Background',
            });
    

    However in my example below I want to run a larger portion of a script, including Javascript, as a background process, but the result of each separate process is a variable so I'm not sure if I can combine them. The processes take quite long to run sometimes and I want to continue working while I wait, and also have access to my other Soundflow commands.

    // I want to start background process here
    
    let folderSizeCheckCurrentDropbox = sf.system.exec({
        commandLine: `
                rclone size --json "${rcloneFolderDropbox}"
                `,
        executionMode: 'Background',
    }).result;
    
    const objDropbox = JSON.parse(folderSizeCheckCurrentDropbox);
    let folderSizeCheckCurrentDropboxValue = objDropbox.bytes;
    
    let folderSizeCheckCurrentGoogleDrive = sf.system.exec({
        commandLine: `
                rclone size --json "${rcloneFolderGoogleDrive}"
                `,
        executionMode: 'Background',
    }).result;
    
    const objGoogleDrive = JSON.parse(folderSizeCheckCurrentGoogleDrive);
    let folderSizeCheckCurrentGoogleDriveValue = objGoogleDrive.bytes;
    
    // This is the end of the section that should run in the background
    

    Is there a way of putting normal Javascript or Soundflow code inside a background process?

    • 0 replies