Skip to main content

Flow Scripts

Creating a Script

Each script must have the following a starting comment block describing the script and a Script function that will be the entry point of the script.

Script Comment Block

/**
* Requires a 7Zip tool to be configured and will zip files
* @author John Andrews
* @version 0.6.1.900
* @help Some help shown at the top of the flow element editor
* @param {string} ArchiveFile The name of the zip file to create, if empty a random name will be used
* @param {string} Pattern The filename pattern to use, eg *.txt
* @param {bool} SetWorkingFileToZip If the working file in the flow should be set to the newly created zip file
* @param {('aac'|'ac3'|'opus')[]} AudioCodecs An array of audio codecs
* @param {('hevc'|'h264'|'av1')} Codec A single video codec to pick from
* @output Zip file created
*/
  • The text before the first @ is the description of the Script
  • @author [optional] The person who created the script
  • @help [optional] Help that is shown at the top of the flow element editor
  • @version [optional] the version of the script
  • @param {type} [name][description]
    • Type: tells the UI what type of input this is, available options are "string", "bool", "int"
    • Name: The variable name passed in to the function, no spaces are allowed
    • Description: everything after name
  • @output these the possible output connections this function has. The order is import, the first @ouput will be "Output 1", 2nd will be "Output 2" etc.

Entry Point

  • The script must have a "Script" function as the entry point
  • The script will have the variables defined in the comments passed into the script when called
function Script(ArchiveFile, Pattern, SetWorkingFileToZip)

Script Parameters

TypeFieldExample
String{string}@param {string} MyString this is a basic string
Boolean{bool}@param {bool} MyBool this is a basic boolean
Integer{int}@param {int} MyInt this is a integer boolean
Select{('a', "With 'quote'", 'c')}See Below
Multi-Select{('a', "With 'quote'", 'c')[]}See Below

Select

@param {('aac'|'ac3'|'opus')} MySelect Single value

Multi-Select

param {('aac'|'ac3'|'opus')[]} MyMultiSelect an array of values

Complete Example

/**
* Requires a 7Zip tool to be configured and will zip files
* @author John Andrews
* @version 0.6.1.900
* @param {string} ArchiveFile The name of hte zip file to create, if empty a random name will be used
* @param {string} Pattern The filename pattern to use, eg *.txt
* @param {bool} SetWorkingFileToZip If the working file in the flow should be set to the newly created zip file
* @output Zip file created
*/
function Script(ArchiveFile, Pattern, SetWorkingFileToZip)
{
let output = '' + ArchiveFile; // ensures ArchiveFile is a string
if(!output || output.trim().length == 0)
output = Flow.TempPath + '/' + Flow.NewGuid() + '.zip';
Logger.ILog('Output: ' + output);
let sevenZip = Flow.GetToolPath('7zip');

let process = Flow.Execute({
command: sevenZip,
argumentList: [
'a',
output,
Pattern
]
});

if(process.exitCode !== 0){
Logger.ELog('Failed to zip: ' + process.exitCode);
return -1;
}

if(SetWorkingFileToZip)
Flow.SetWorkingFile(output);
return 1;
}