Slide 1

Slide 1 text

fringe.js An introduction to ExtendScript

Slide 2

Slide 2 text

fringe.js An introduction to ExtendScript Not an actual library!

Slide 3

Slide 3 text

@polarblau

Slide 4

Slide 4 text

ExtendScript

Slide 5

Slide 5 text

[Show of Hands]

Slide 6

Slide 6 text

No content

Slide 7

Slide 7 text

Extensions

Slide 8

Slide 8 text

Complexity Macros & Actions Scripts Plugins

Slide 9

Slide 9 text

Complexity Macros & Actions Scripts Plugins Automation Additional functionality

Slide 10

Slide 10 text

= Automation on steroids

Slide 11

Slide 11 text

Why care? (Why do I care?)

Slide 12

Slide 12 text

Personal background PS & AI are constants in personal toolkit

Slide 13

Slide 13 text

Laziness

Slide 14

Slide 14 text

Time Task size “Manual” labor

Slide 15

Slide 15 text

Time Task size “Manual” labor

Slide 16

Slide 16 text

Time Task size Frustration

Slide 17

Slide 17 text

Time Task size Write script

Slide 18

Slide 18 text

Time Task size Run script

Slide 19

Slide 19 text

Time Task size

Slide 20

Slide 20 text

Curiosity

Slide 21

Slide 21 text

“ “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

Slide 22

Slide 22 text

Why care? (Why could you possibly care?)

Slide 23

Slide 23 text

Low hanging fruit

Slide 24

Slide 24 text

VBScript Javascript AppleScript Javascript

Slide 25

Slide 25 text

Javascript!

Slide 26

Slide 26 text

Didn’t your mom tell you…?

Slide 27

Slide 27 text

No content

Slide 28

Slide 28 text

The user’s perspective

Slide 29

Slide 29 text

No content

Slide 30

Slide 30 text

No content

Slide 31

Slide 31 text

[Example]

Slide 32

Slide 32 text

v

Slide 33

Slide 33 text

The toolkit

Slide 34

Slide 34 text

No content

Slide 35

Slide 35 text

No content

Slide 36

Slide 36 text

No content

Slide 37

Slide 37 text

Document window

Slide 38

Slide 38 text

Document window Console

Slide 39

Slide 39 text

Target application

Slide 40

Slide 40 text

Engine of target application

Slide 41

Slide 41 text

Run script

Slide 42

Slide 42 text

Control execution

Slide 43

Slide 43 text

Debugging

Slide 44

Slide 44 text

No content

Slide 45

Slide 45 text

No content

Slide 46

Slide 46 text

Export as binary

Slide 47

Slide 47 text

javascript_tools_guide_cs3.pdf http://bit.ly/PNo7h4

Slide 48

Slide 48 text

.js

Slide 49

Slide 49 text

.jsx

Slide 50

Slide 50 text

“ “In addition to implementing the JavaScript language according to the ECMA JavaScript specification, ExtendScript provides certain additional features and utilities.” — ADOBE, Javascript Tools Guide

Slide 51

Slide 51 text

Overview:

Slide 52

Slide 52 text

DOM

Slide 53

Slide 53 text

Application Document Pages Channels Layers Text frames …

Slide 54

Slide 54 text

Illustrator (Scripting Guide)

Slide 55

Slide 55 text

var doc = app.activeDocument, sel = doc.selection;

Slide 56

Slide 56 text

doc.textFrames[0].parents // -> returns layer or group

Slide 57

Slide 57 text

File system access

Slide 58

Slide 58 text

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

Slide 59

Slide 59 text

// 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); } }

Slide 60

Slide 60 text

Inter–application communication

Slide 61

Slide 61 text

Limited set of cross DOM functions // e.g. open file in ID from PS indesign.open(file) // script {String} photoshop.executeScript(script);

Slide 62

Slide 62 text

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;"

Slide 63

Slide 63 text

// define result handler callback bt.onResult = function(returnBtObj) { // .processResult() is defined elsewhere processResult(returnBtObj.body); } // send the message asynchronously bt.send(); }

Slide 64

Slide 64 text

External communication

Slide 65

Slide 65 text

FTP var file = new File('/c/Photo.jpg'), ftp = new FtpConnection('ftp://server'); ftp.put(file,'Photo.jpg'); ftp.close(); file.close();

Slide 66

Slide 66 text

HTTP var http = new HttpConnection("http://example.com") ; http.request = "foo=bar"; http.method = "POST" http.execute();

Slide 67

Slide 67 text

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(); }

Slide 68

Slide 68 text

External libraries

Slide 69

Slide 69 text

“ “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

Slide 70

Slide 70 text

ScriptUI

Slide 71

Slide 71 text

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 ();

Slide 72

Slide 72 text

No content

Slide 73

Slide 73 text

var win = new Window("dialog"); var columns = win.add("group"); columns.spacing = 0; var header = { numberOfColumns: 1, showHeaders : true, columnWidths : [80] };

Slide 74

Slide 74 text

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();

Slide 75

Slide 75 text

No content

Slide 76

Slide 76 text

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 ();

Slide 77

Slide 77 text

No content

Slide 78

Slide 78 text

http://www.kahrel.plus.com/indesign/ scriptui-1-12.pdf

Slide 79

Slide 79 text

Miscellaneous

Slide 80

Slide 80 text

$ // Object properties, e.g. $.fileName // Name of current file $.os // Operating System $.screens // # of attached screens …

Slide 81

Slide 81 text

$ // Object functions, e.g. $.colorPicker // System picker $.sleep // Suspend thread temp. $.write // Log to console …

Slide 82

Slide 82 text

// execute script in Photoshop CS3 #target "photoshop-10.0"

Slide 83

Slide 83 text

// Include files #include "other/file.jsx"

Slide 84

Slide 84 text

Any frameworks?

Slide 85

Slide 85 text

extendables by Stijn Debrouwere

Slide 86

Slide 86 text

Not actively developed Originally designed for ID Python

Slide 87

Slide 87 text

#include "../extendables.jsx"; var ui = require("ui");

Slide 88

Slide 88 text

UI

Slide 89

Slide 89 text

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..."; });

Slide 90

Slide 90 text

HTTP

Slide 91

Slide 91 text

var http = require("http"); if (!http.has_internet_access()) { throw new Error("No internet, no recipes."); } var response = http.get("http://example.com");

Slide 92

Slide 92 text

Testing

Slide 93

Slide 93 text

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); }); });

Slide 94

Slide 94 text

Logging

Slide 95

Slide 95 text

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}); }

Slide 96

Slide 96 text

Extensions

Slide 97

Slide 97 text

Array#flatten [1,2,[3,4,[5,6]]].flatten() // -> [1,2,3,4,5,6]

Slide 98

Slide 98 text

Array#filter #pluck #forEach #map …

Slide 99

Slide 99 text

String#format "Hello {}. {}".format("world", "Bye!"); var person = { name: "Flo", job: "Animal wrangler" }; "{name} is a {job} by day".format(person);

Slide 100

Slide 100 text

String#trim #startswith …

Slide 101

Slide 101 text

Object#is [].is(Array) // -> true

Slide 102

Slide 102 text

Object#keys #merge #extend #has …

Slide 103

Slide 103 text

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");

Slide 104

Slide 104 text

http://extendables.org/ https://github.com/stdbrouw/ extendables

Slide 105

Slide 105 text

Got some ideas?

Slide 106

Slide 106 text

http://wwwimages.adobe.com/ www.adobe.com/content/dam/Adobe/en/ devnet/pdf/illustrator/pdfs/ adobe_intro_to_scripting.pdf http://bit.ly/PrPDfQ

Slide 107

Slide 107 text

http://www.adobe.com/devnet.html

Slide 108

Slide 108 text

http://www.adobe.com/devnet/ photoshop/scripting.html

Slide 109

Slide 109 text

Kiitos! Thanks!