Archive for the ‘Javascript’ Category

Script to replace Smart Objects in Photoshop files

Wednesday, May 15th, 2013

Wanting to share graphical assets between multiple Photoshop files and update them at once just like when linking images to Illustrator files, I wrote a script that can replace Smart Object layers with external .psb files. This actually is my first Photoshop script. Any suggestions for improvements would be much appreciated.

How to use it:

  1. Install the script, place the .jsx file in the Scripts folder (Photoshop CS/Presets/Scripts) and restart the application. The script appears in the Scripts menu (File > Scripts)
  2. Create the graphical assets as .psb files and save them in a folder named “assets”
    The file names must start with the prefix “so_” and end with “.psb”. (the folder name and the prefix can be altered in the variables in the beginning of the code.)
  3. In the psd(b) files in which you want to use these assets, create Smart Object layers that have the same names as .psb files without the extension, e.g. a layer named “so_mail_icon” links to assets/so_mail_icon.psb.
  4. Run the script. The smart layers will be replaced with the .psb files.

Download Sample

var prefix = "so_";
var assetPath = "assets/"

var count = 0;
listLayersets(app.activeDocument);
listLayers(app.activeDocument);
var path;

function listLayersets(pointer) {
     for (var i = 0; i < pointer.layerSets.length; i++) {
        var layerset = pointer.layerSets[i];
        listLayers (layerset);
    }
}

function listLayers(pointer) {
    for (var i = 0; i < pointer.artLayers.length; i++) {
        var layer = pointer.artLayers[i];
        if (layer.name.indexOf(prefix) == 0) {
            if (layer.kind == "LayerKind.SMARTOBJECT") {
                app.activeDocument.activeLayer = layer;
                replaceSO (app.activeDocument.path + "/" + assetPath + layer.name + ".psb");
            }
         }
    }
}

function replaceSO (newFile) {
	var id = stringIDToTypeID( "placedLayerReplaceContents" );
    var desc = new ActionDescriptor();
    var idn = charIDToTypeID("null");
    desc3.putPath( idn, new File(newFile));
    var idp = charIDToTypeID("PgNm");
    desc3.putInteger(idp, 1);
	executeAction(id, desc, DialogModes.NO);
	return app.activeDocument.activeLayer
};

localstorage

Wednesday, May 4th, 2011

A simple test on localstorage object. The input fields keep retaining the previous values

http://www.kynd.info/library/localStorage/

HTML5 – canvas

Monday, May 3rd, 2010

As html5 and canvas are getting much interest lately, I’ve tested the very basic functions of canvas even if a little belated.
The performance and results of the samples depends on the spec of the browser. So try them on the latest versions if possible, though most of them works even on the Internet Explorer which originally didn’t support canvas(thanks to excanvas).

html5-canvas

iPad Detection

Thursday, April 15th, 2010

I note here not to forget.
iPad Detection Using JavaScript or PHP

Related Posts with Thumbnails