Skip to content

Instantly share code, notes, and snippets.

View GoodBoyNinja's full-sized avatar
You are a brain. Be a kind brain!

Good Boy Ninja GoodBoyNinja

You are a brain. Be a kind brain!
View GitHub Profile
GoodBoyNinja / usefuleIncludes.jsx
Last active November 17, 2023 22:26
Things that are useful to include in your script file. Some of them are functionalities poly fills from later versions of JavaScript. This also includes json2.js functions (JSON.parse, JSON.stringify) and other useful functions for working with arrays and objects
View usefuleIncludes.jsx
(function includes() {
(function IncludeIsArray() {
if (!Array.isArray) {
Array.isArray = function (arg) {
return === "[object Array]";
(function includeJSON() {
GoodBoyNinja / mouse.jsx
Last active November 17, 2023 22:26
a mouse object for ExtendScript. This creates a new object called mouse which you can manually (only) update to keep track of your clicks. For example, on a right click you can use Mouse.setRight() to set the "last" property to 2 (mouse button of index 2). Then you can check if your latest click was a right click by calling Mouse.lastIsRight(), …
View mouse.jsx
var Mouse = new (function () {
var mouse = this;
this.last = 0;
this.setLeft = function () {
mouse.last = 0;
this.setMiddle = function () {
mouse.last = 1;
GoodBoyNinja / genRand.jsx
Created June 7, 2021 21:04
Generate a random number between a min and a max. Limit the decimal places to a specific amount if you want to. Set decimal places to 0 to return a rounded int.
View genRand.jsx
function genRand(min, max, decimalPlaces) {
// you could add some error checking to make sure all arguments exist
var result = Math.random() * (max - min) + min;
if (decimalPlaces > 0) {
var power = Math.pow(10, decimalPlaces);
var result = Math.floor(result * power) / power;
if (decimalPlaces === 0) {
result = Math.round(result);
GoodBoyNinja / lerp.jsx
Created June 7, 2021 21:02
A basic lerp function for ExtendScript. amt is similar to t in the more conventional naming of lerp. This function is similar to the Linear function inside After-Effects expression, however it does not let you map the range to something else, and the argument list order is different. This function works with arrays of numbers as well (for exampl…
View lerp.jsx
function lerp(start, end, amt) {
if (start == undefined || end == undefined || amt == undefined) {
// can't lerp, start end amount is missing
if (start !== undefined) {
return start;
return 0;
function oneDLerp(start, end, amt) {
GoodBoyNinja / filterColorProps.jsx
Last active November 17, 2023 22:26
filter color properties out of an array of properties.
View filterColorProps.jsx
function FilterColorProperties(propsArray) {
var result = [];
//getting selected colors...
var propsArray =
propsArray == undefined ? (app.project.activeItem.selectedProperties || []) : propsArray;
if (!propsArray || !propsArray.length) {
// no selected colors because no properties are selected
return result;
GoodBoyNinja / freezeLayerAtTime.jsx
Created June 7, 2021 20:53
pass a layer to freeze it where the time indicator currently is. Pass a specific time (in seconds) to freeze somewhere else.
View freezeLayerAtTime.jsx
function freezeLayerAtCurrentTime(layer, specificTime) {
if (!layer) {
// no layer
return false
layer.timeRemapEnabled = true;
var timeRemapProp = layer("ADBE Time Remapping");
GoodBoyNinja / separateGroupsAndProperties.jsx
Created June 7, 2021 20:51
This function takes an array of properties and separates them into properties, groups and indexed groups. It returns an object, you you can later on access the array you are interested in. Example: var variableName = separateGroupsAndProperties([app.project.activeItem.selectedProperties]).groups;
View separateGroupsAndProperties.jsx
function separateGroupsAndProperties (propsArray) {
// sorting an array of props to props an group... return an object
var resultObject = {
all: [],
props: [],
groups: [],
indexedGroups: [],
GoodBoyNinja / getItemsByName.jsx
Created June 7, 2021 20:46
Loops through the After-Effects project items and returns an array of items that match the name that you passed into the function
View getItemsByName.jsx
function GetItemsByName (nameString) {
// returns array of found matches
if (!nameString) {
return false;
var matches = [];
for (var i = 1; i <= app.project.numItems; i++) {
var crnt = app.project.item(i);
var crntName =;
GoodBoyNinja / checkGumroadLicense.jsx
Created June 7, 2021 20:42
If you are planning on uploading a script to Gumroad you can use this function in order to contact Gumroad through the script, and receive a response. Note that it uses JSON.parse, which means you need to have json2.js included in your code in order to convert the response into an object. You can learn more about it here:…
View checkGumroadLicense.jsx
function GumrdLicenseRequest(licenseKeyInput, incrementUseCount, showDialogs) {
// better check here if there is access to files and network
var showDialogs = (showDialogs == undefined) ? true : showDialogs;
licenseKeyInput == undefined ? undefined : licenseKeyInput;
incrementUseCount == undefined ? false : String(incrementUseCount);
if (
GoodBoyNinja / pressed.jsx
Last active November 17, 2023 22:27
A small group of functions to let you intuitively check one of ctrl, shift or alt is pressed. Example: alert(pressed.shift())
View pressed.jsx
var pressed = new (function () {
this.shift = function () {
if (ScriptUI.environment.keyboardState.shiftKey) {
return true;
return false;
this.alt = function () {
if (ScriptUI.environment.keyboardState.altKey) {
return true;