├── package.json ├── README.md ├── LICENSE └── main.js /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "generator-getting-started", 3 | "version": "1.0.0", 4 | "description": "Getting started Adobe Generator", 5 | "main": "main.js", 6 | "generator-core-version": "1 - 3.1", 7 | "repository": { 8 | "type": "git", 9 | "url": "https://github.com/tomkrcha/generator-getting-started" 10 | }, 11 | "license": "Public Domain", 12 | "readmeFilename": "README.md", 13 | "scripts": { 14 | "test": "grunt test" 15 | }, 16 | "dependencies": { 17 | }, 18 | "devDependencies": { 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | generator-getting-started 2 | ========================= 3 | 4 | Adobe Generator Getting Started Tutorial - Scripting Photoshop with JavaScript via Node.js 5 | 6 | Follow the tutorial instructions on my blog: http://tomkrcha.com/?p=3896 7 | 8 | Created by Tom Krcha https://twitter.com/tomkrcha 9 | 10 | --------- 11 | Built-in Generator log files can be found here: 12 | 13 | Mac: 14 | /Users/[your username]/Library/Logs/Adobe/Adobe Photoshop CC/Generator 15 | 16 | Windows: 17 | C:\Users\[your username]\AppData\Roaming\Adobe\Adobe Photoshop 18 | CC\Generator\logs 19 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | This is free and unencumbered software released into the public domain. 2 | 3 | Anyone is free to copy, modify, publish, use, compile, sell, or 4 | distribute this software, either in source code form or as a compiled 5 | binary, for any purpose, commercial or non-commercial, and by any 6 | means. 7 | 8 | In jurisdictions that recognize copyright laws, the author or authors 9 | of this software dedicate any and all copyright interest in the 10 | software to the public domain. We make this dedication for the benefit 11 | of the public at large and to the detriment of our heirs and 12 | successors. We intend this dedication to be an overt act of 13 | relinquishment in perpetuity of all present and future rights to this 14 | software under copyright law. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR 20 | OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 21 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 | OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | For more information, please refer to 25 | -------------------------------------------------------------------------------- /main.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013 Adobe Systems Incorporated. All rights reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | * 22 | */ 23 | 24 | // Tutorial script by Tom Krcha (Twitter: @tomkrcha) 25 | 26 | (function () { 27 | "use strict"; 28 | 29 | var PLUGIN_ID = require("./package.json").name, 30 | MENU_ID = "tutorial", 31 | MENU_LABEL = "$$$/JavaScripts/Generator/Tutorial/Menu=Tutorial"; 32 | 33 | var _generator = null, 34 | _currentDocumentId = null, 35 | _config = null; 36 | 37 | /*********** INIT ***********/ 38 | 39 | function init(generator, config) { 40 | _generator = generator; 41 | _config = config; 42 | 43 | console.log("initializing generator getting started tutorial with config %j", _config); 44 | 45 | _generator.addMenuItem(MENU_ID, MENU_LABEL, true, false).then( 46 | function () { 47 | console.log("Menu created", MENU_ID); 48 | }, function () { 49 | console.error("Menu creation failed", MENU_ID); 50 | } 51 | ); 52 | _generator.onPhotoshopEvent("generatorMenuChanged", handleGeneratorMenuClicked); 53 | 54 | function initLater() { 55 | // Flip foreground color 56 | var flipColorsExtendScript = "var color = app.foregroundColor; color.rgb.red = 255 - color.rgb.red; color.rgb.green = 255 - color.rgb.green; color.rgb.blue = 255 - color.rgb.blue; app.foregroundColor = color;"; 57 | sendJavascript(flipColorsExtendScript); 58 | 59 | _generator.onPhotoshopEvent("currentDocumentChanged", handleCurrentDocumentChanged); 60 | _generator.onPhotoshopEvent("imageChanged", handleImageChanged); 61 | _generator.onPhotoshopEvent("toolChanged", handleToolChanged); 62 | requestEntireDocument(); 63 | 64 | } 65 | 66 | process.nextTick(initLater); 67 | 68 | 69 | 70 | } 71 | 72 | /*********** EVENTS ***********/ 73 | 74 | function handleCurrentDocumentChanged(id) { 75 | console.log("handleCurrentDocumentChanged: "+id) 76 | setCurrentDocumentId(id); 77 | } 78 | 79 | function handleImageChanged(document) { 80 | console.log("Image " + document.id + " was changed:");//, stringify(document)); 81 | } 82 | 83 | function handleToolChanged(document){ 84 | console.log("Tool changed " + document.id + " was changed:");//, stringify(document)); 85 | } 86 | 87 | function handleGeneratorMenuClicked(event) { 88 | // Ignore changes to other menus 89 | var menu = event.generatorMenuChanged; 90 | if (!menu || menu.name !== MENU_ID) { 91 | return; 92 | } 93 | 94 | var startingMenuState = _generator.getMenuState(menu.name); 95 | console.log("Menu event %s, starting state %s", stringify(event), stringify(startingMenuState)); 96 | } 97 | 98 | /*********** CALLS ***********/ 99 | 100 | function requestEntireDocument(documentId) { 101 | if (!documentId) { 102 | console.log("Determining the current document ID"); 103 | } 104 | 105 | _generator.getDocumentInfo(documentId).then( 106 | function (document) { 107 | console.log("Received complete document:", stringify(document)); 108 | }, 109 | function (err) { 110 | console.error("[Tutorial] Error in getDocumentInfo:", err); 111 | } 112 | ).done(); 113 | } 114 | 115 | function updateMenuState(enabled) { 116 | console.log("Setting menu state to", enabled); 117 | _generator.toggleMenu(MENU_ID, true, enabled); 118 | } 119 | 120 | /*********** HELPERS ***********/ 121 | 122 | 123 | function sendJavascript(str){ 124 | _generator.evaluateJSXString(str).then( 125 | function(result){ 126 | console.log(result); 127 | }, 128 | function(err){ 129 | console.log(err); 130 | }); 131 | } 132 | 133 | function setCurrentDocumentId(id) { 134 | if (_currentDocumentId === id) { 135 | return; 136 | } 137 | console.log("Current document ID:", id); 138 | _currentDocumentId = id; 139 | } 140 | 141 | function stringify(object) { 142 | try { 143 | return JSON.stringify(object, null, " "); 144 | } catch (e) { 145 | console.error(e); 146 | } 147 | return String(object); 148 | } 149 | 150 | exports.init = init; 151 | 152 | // Unit test function exports 153 | exports._setConfig = function (config) { _config = config; }; 154 | 155 | }()); --------------------------------------------------------------------------------