Skip to content

Instantly share code, notes, and snippets.

@jasonrhodes
Last active April 10, 2019 09:49
Show Gist options
  • Save jasonrhodes/5286526 to your computer and use it in GitHub Desktop.
Save jasonrhodes/5286526 to your computer and use it in GitHub Desktop.
Include the minified version at the top of any of our .jsx script files and then you can include files from adobe_scripts/lib just by calling Libraries.include("subdir/myscript")
// Assumes that your script is somewhere within a folder called "adobe_scripts" and
// that you store your includable files relative to `adobe_scripts/lib/`
// indexOf polyfill from https://gist.github.com/atk/1034425
[].indexOf||(Array.prototype.indexOf=function(a,b,c){for(c=this.length,b=(c+~~b)%c;b<c&&(!(b in this)||this[b]!==a);b++);return b^c?b:-1;});
var Libraries = (function (libPath) {
return {
include: function (path) {
if (!path.match(/\.jsx$/i)) {
path = path + ".jsx";
}
return $.evalFile(libPath + path);
}
};
})($.fileName.split("/").splice(0, $.fileName.split("/").indexOf("adobe_scripts") + 1).join("/") + "/lib/");
// Minified version, to include at the top of any .jsx script file
/**
* Libraries.include(path) -- path must be relative to adobe_scripts/lib/
* See: https://gist.github.com/jasonrhodes/5286526
*/
[].indexOf||(Array.prototype.indexOf=function(a,b,c){for(c=this.length,b=(c+~~b)%c;b<c&&(!(b in this)||this[b]!==a);b++);return b^c?b:-1;});
var Libraries=function(a){return{include:function(b){return b.match(/\.jsx$/i)||(b+=".jsx"),$.evalFile(a+b)}}}($.fileName.split("/").splice(0,$.fileName.split("/").indexOf("adobe_scripts")+1).join("/")+"/lib/");
@toddfast
Copy link

Fantastic, thanks!

@Nathanpmyoung
Copy link

Hey I'm trying to use this with Illustrator and keep getting the error:

Error 21: Undefined is not an object.
Line 6 -> var Libraries = (function(libpath){

Thank you so much for you time and no pressure, but do you know what's causing this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment