Upgrade to Pro — share decks privately, control downloads, hide ads and more …

fringe.js — An Introduction to ExtendScript

fringe.js — An Introduction to ExtendScript

Use Javascript outside the browser *or* the server? — Adobe’s ExtendScript Toolkit has been around for quite a while, yet few Javascript developers seem to know about the possibility to use their existing knowledge to extend Adobe’s Creative Suite applications through this powerful scripting environment.
This talk will give an overview on what the toolkit is, how it works and why you as Javascript developers might want to care.

Florian Plank

August 29, 2012
Tweet

More Decks by Florian Plank

Other Decks in Programming

Transcript

  1. “ “Scripting isn’t programming. You don’t need a degree in

    computer science or mathematics to write basic scripts that automate a wide variety of common tasks.” — ADOBE, Introduction to scripting
  2. v

  3. .js

  4. “ “In addition to implementing the JavaScript language according to

    the ECMA JavaScript specification, ExtendScript provides certain additional features and utilities.” — ADOBE, Javascript Tools Guide
  5. DOM

  6. File([path]); //can return a Folder object new File([path]); //always returns

    a File object Folder([path]); //can return a File object new Folder([path]); //always returns a Folder object
  7. // export from AI to PS function exportFileToPSD (destination) {

    if (app.documents.length > 0) { var options = new ExportOptionsPhotoshop(), type = ExportType.PHOTOSHOP, file = new File(destination); exportOptions.resolution = 150; doc.exportFile(file, type, options); } }
  8. Limited set of cross DOM functions // e.g. open file

    in ID from PS indesign.open(file) // script {String} photoshop.executeScript(script);
  9. BridgeTalk #target "photoshop-10.0" // app available? var targetApp = BridgeTalk.getSpecifier("bridge-2.0");

    if(targetApp) { // construct a message object var bt = new BridgeTalk; // the message is intended for Adobe Bridge CS3 bt.target = targetApp; // the script to evaluate bt.body = "new Document('C:\\BridgeScripts');" + "app.document.target.children.length;"
  10. // define result handler callback bt.onResult = function(returnBtObj) { //

    .processResult() is defined elsewhere processResult(returnBtObj.body); } // send the message asynchronously bt.send(); }
  11. FTP var file = new File('/c/Photo.jpg'), ftp = new FtpConnection('ftp://server');

    ftp.put(file,'Photo.jpg'); ftp.close(); file.close();
  12. Socket var reply = "", conn = new Socket; //

    access Adobe's home page if (conn.open ("www.foo.com:80")) { // send a HTTP GET request conn.write("GET /index.html HTTP/1.0\n\n"); // and read the server's reply reply = conn.read(999999); conn.close(); }
  13. “ “You can extend the JavaScript DOM for an application

    by writing a C or C++ shared library, compiling it for the platform you are using, and loading it into JavaScript as an ExternalObject Object. ” — ADOBE, Javascript Tools Guide
  14. var win = new Window("dialog", "Form"); win.orientation = "row"; //

    label win.add ("statictext", undefined, "Name:"); // input field var nameInput = win.add ("edittext", undefined, "John"); nameInput.characters = 30; nameInput.active = true; win.show ();
  15. var win = new Window("dialog"); var columns = win.add("group"); columns.spacing

    = 0; var header = { numberOfColumns: 1, showHeaders : true, columnWidths : [80] };
  16. header.columnTitles = ["French"]; var col1 = columns.add("listbox", undefined, ["Un","Deux","Trois"], header);

    header.columnTitles = ["English"]; var col2 = columns.add("listbox", undefined, ["One","Two","Three"], header); header.columnTitles = ["Dutch"]; var col3 = columns.add("listbox", undefined, ["Een","Twee","Drie"], header); win.show();
  17. var win = new Window("dialog"), inputField = win.add("edittext", undefined, "Abcdefg"),

    button = win.add("button", undefined, "Convert to upper case"); win.add("button", undefined, "OK"); button.onClick = function() { inputField.text = inputField.text.toUpperCase(); } win.show ();
  18. $ // Object properties, e.g. $.fileName // Name of current

    file $.os // Operating System $.screens // # of attached screens …
  19. $ // Object functions, e.g. $.colorPicker // System picker $.sleep

    // Suspend thread temp. $.write // Log to console …
  20. UI

  21. var styling = { 'big': { 'size': [400, 15], 'justify':

    'center' } } var dialog = new ui.Dialog("I'm hungry").with(styling); dialog.text('food', 'Food!').using('big') .button('ok', 'Sure thing!') .button('no', 'No thanks'); dialog.ok.on('click').do(function(){ dialog.food.text = "Wait a sec, coming up!"; dialog.ok.text = "Hmm..."; });
  22. var http = require("http"); if (!http.has_internet_access()) { throw new Error("No

    internet, no recipes."); } var response = http.get("http://example.com");
  23. describe('Calculator', function () { var counter = 0 it('can add

    a number', function () { counter = counter + 2; // counter was 0 before expect(bar).toEqual(2); }); it('can multiply a number', function () { counter = counter * 5; // counter was 2 before expect(bar).toEqual(10); }); });
  24. var logging = require("logging"); // all logs end up in

    extendables/log var log = new Log("example.log"); try { throw new Error(); } catch (error) { log.debug("Error! will log a debug message now"); log.critical("Something happened: {error} ({env})", {'error': error, 'env': $.os}); }
  25. String#format "Hello {}. {}".format("world", "Bye!"); var person = { name:

    "Flo", job: "Animal wrangler" }; "{name} is a {job} by day".format(person);
  26. File / Folder var documentation = new Folder("doc") .at(Folder.extendables); var

    here = new File($.fileName); var examples = here.parent.files(); var docfiles = documentation.files("*.md");