Skip to content

Instantly share code, notes, and snippets.

View undavide's full-sized avatar

Davide Barranca undavide

View GitHub Profile
@undavide
undavide / DemoGist.jsx
Created June 25, 2015 11:18
Demo Gist for Photoshop Scripting Cookbook
$.writeln("Hello World!");
@undavide
undavide / ToggleScriptingListener.jsx
Created June 25, 2015 11:26
Toggle ScriptingListener Logging
// Credits: Tom Ruark
// Switch OFF ScriptingListener output
var listenerID = stringIDToTypeID("AdobeScriptListener ScriptListener");
var keyLogID = charIDToTypeID('Log ');
var d = new ActionDescriptor;
d.putBoolean(keyLogID, false);
executeAction(listenerID, d, DialogModes.NO);
// Switch ON ScriptingListener output
@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...