Using an 'include' to reference an external script

A neat trick is to move all of your own functions that you've written or created using the ScriptingListener into an external .js file. Then you can use an 'include' to reference the .js file containing your function library, keeping the script your working on neat and tidy.

Create a function:

function makeSlice() {
var id14 = charIDToTypeID( "Mk  " );
  var desc5 = new ActionDescriptor();
  var id15 = charIDToTypeID( "null" );
	var ref2 = new ActionReference();
	var id16 = stringIDToTypeID( "slice" );
	ref2.putClass( id16 );
  desc5.putReference( id15, ref2 );
  var id17 = charIDToTypeID( "Usng" );
	var desc6 = new ActionDescriptor();
	var id18 = charIDToTypeID( "Type" );
	var id19 = stringIDToTypeID( "sliceType" );
	var id20 = stringIDToTypeID( "user" );
	desc6.putEnumerated( id18, id19, id20 );
	var id21 = charIDToTypeID( "At  " );
	  var desc7 = new ActionDescriptor();
	  var id22 = charIDToTypeID( "Top " );
	  var id23 = charIDToTypeID( "#Rlt" );
	  desc7.putUnitDouble( id22, id23, 92.000000 );
	  var id24 = charIDToTypeID( "Left" );
	  var id25 = charIDToTypeID( "#Rlt" );
	  desc7.putUnitDouble( id24, id25, 62.000000 );
	  var id26 = charIDToTypeID( "Btom" );
	  var id27 = charIDToTypeID( "#Rlt" );
	  desc7.putUnitDouble( id26, id27, 184.000000 );
	  var id28 = charIDToTypeID( "Rght" );
	  var id29 = charIDToTypeID( "#Rlt" );
	  desc7.putUnitDouble( id28, id29, 231.000000 );
	var id30 = charIDToTypeID( "Rctn" );
	desc6.putObject( id21, id30, desc7 );
  var id31 = stringIDToTypeID( "slice" );
  desc5.putObject( id17, id31, desc6 );
executeAction( id14, desc5, DialogModes.NO );
}

Save the file as 'function_lib.js' in the Photoshop's 'Scripts' directory:

Next create a new script. Use an 'Include' to reference 'function_lib.js' file:

// Includes an external .js file

// @include 'function_lib.js'

Note: the 'Include' code will execute even though it looks like a comment.

Call the function 'makeSlice' from the 'function_lib.js' file:

makeSlice();

Save the file as 'my_script.js' in the Photoshop's 'Scripts' directory:

Run the script called 'my_script.js'.

If you want to comment out an 'Include' you must double comment it using /* */.

/*// Includes an external .js file

// @include 'function_lib.js'*/