Skip to content

Instantly share code, notes, and snippets.

View undavide's full-sized avatar

Davide Barranca undavide

  • Sr. Developer Relations Engineer at Adobe
  • Bologna (countryside), Italy
  • 18:07 (UTC +02:00)
View GitHub Profile
@undavide
undavide / DemoGist.jsx
Created June 25, 2015 11:18
Demo Gist for Photoshop Scripting Cookbook
$.writeln("Hello World!");
@undavide
undavide / GetPresetsNames.jsx
Created June 25, 2015 18:33
Get Presets Names
function s(str) { return stringIDToTypeID(str) }
var ref = new ActionReference();
ref.putProperty(s('property'), s('presetManager'));
ref.putEnumerated(s('application'), s('ordinal'), s('targetEnum'));
var desc = executeActionGet(ref).getList(s('presetManager'));
var presetDesc = undefined,
lists = desc.count;
for (var i = 0; i < lists; i++) {
@undavide
undavide / panels102_5.js
Last active March 14, 2018 21:35
Passing primitive data as a parameter
// JS file (panel)
var sharpeningStrength = 225;
csInterface.evalScript('addSharpeningForWeb(' + sharpeningStrength + ')');
// JSX file (Photoshop)
function addSharpeningForWeb(strength) {
// ... you can now use the strength param here
}
@undavide
undavide / panels102_4.js
Last active March 14, 2018 21:35
JSX function
// JSX file (Photoshop)
function addSharpeningForWeb() {
// ... smart Photoshop scripting code here
}
@undavide
undavide / panels102_3.js
Last active March 14, 2018 21:36
Run a JSX function
// JS file (panel)
csInterface.evalScript('addSharpeningForWeb()');
@undavide
undavide / panels102_2.js
Last active March 14, 2018 21:36
Run the evalScript method
// JS file (panel)
var csInterface = new CSInterface();
csInterface.evalScript('alert("Hello World!")');
@undavide
undavide / panels102_1.js
Last active March 14, 2018 21:36
Instantiate a CSInterface class
// JS file (panel)
var csInterface = new CSInterface();
@undavide
undavide / panels201_3.js
Created March 14, 2018 21:43
Including a callback
// JS file (panel)
// ...
csInterface.evalScript('addSharpeningForWeb(' + paramString + ')', function(res) {
// "res" is the response that comes from Photoshop
});
// JSX file (Photoshop)
function addSharpeningForWeb(paramObj) {
// ... lots of code here
return true;
@undavide
undavide / panels201_4.js
Last active March 14, 2018 21:48
Passing a JSON string from the JSX back to the panel
// JS file (panel)
// ...
csInterface.evalScript('getDocumentInfo()', function(res) {
var resObj = JSON.parse(res);
// you have now access to the same docInfo object
});
// JSX file (Photoshop)
function getDocumentInfo() {
//... I just make up data here...
@undavide
undavide / panels201_1.js
Last active April 3, 2018 19:46
Interpolating parameters
// JS file (panel)
var sharpeningStrength = 225,
highlightsProtection = 50,
midtonesProtection = 15,
shadowsProtection = 0,
oldAlgorithm = false,
copyrightString = "© John Doe 2018"
csInterface.evalScript('addSharpeningForWeb(' +
sharpeningStrength + ', ' +