Photoshop 脚本初体验

test.jsx

#target photoshop
app.bringToFront();

var nowTime = new Date();
var PRESOLUTION = 72; 
var startRulerUnits = app.preferences.rulerUnits;
var startTypeUnits = app.preferences.typeUnits;
app.preferences.rulerUnits = Units.PIXELS;
app.preferences.typeUnits = TypeUnits.PIXELS;
var title = "界面测试";

res = "dialog { \
    text:'" + title + " - 直接保存并关闭', \
    group: Group { \
        orientation: 'column', \
        alignChildren: 'left', \
        top: StaticText { \
            text: '默认为直接覆盖保存 - 请注意选择或做好备份' \
        }, \
        timeline: Progressbar { \
            bounds: [0, 0, 300, 10], \
            minvalue: 0, \
            maxvalue:100 \
        } \
        coordinate: Panel { \
            orientation: 'row', \
            text: '需要尺寸', \
            x: Group { \
                orientation: 'row', \
                s: StaticText { text: '宽:' }, \
                e: EditText { preferredSize: [50, 20] } ,\
                p: StaticText { text:'px' }, \
            }, \
            y: Group { \
                orientation: 'row', \
                s: StaticText { text:'高:' }, \
                e: EditText { preferredSize: [50, 20] }, \
                p: StaticText { text:'px' }, \
            } , \
        }, \
        folderO: Group { \
            orientation: 'row', \
            b: Button { \
                text: '待处理文件夹', \
                properties: { name: 'open' } , \
                helpTip: '选择您需要处理的文件所在的文件夹' \
            }, \
            s: EditText  { \
                text: '', \
                preferredSize: [180, 20] \
            }, \
        }, \
    },\
    buttons: Group { \
        orientation: 'row', \
        alignment: 'right', \
        s: StaticText { \
            text: '[ABOUT]' \
        }, \
        btnOk: Button { \
            text: '确定', \
            properties: { name: 'ok' } \
        }, \
        btnCancel: Button { \
            text: '取消', \
            properties: { name: 'cancel' } \
        } \
    }, \
}";

win = new Window (res);


// 选择目标文件夹
var folderOpen = win.group.folderO;
folderOpen.b.onClick = function() {
		var defaultFolder = folderOpen.s.text;
		var testFolder = new Folder(defaultFolder);
		if ( !testFolder.exists ) {
			defaultFolder = "~";
		}
		var selFolder = Folder.selectDialog("选择待处理文件夹", defaultFolder);
		if ( selFolder != null ) {
            folderOpen.s.text = selFolder.fsName;
            folderOpen.s.helpTip = selFolder.fsName.toString();
	    }
}

// 取消
win.buttons.btnCancel.onClick = function () {
	app.preferences.rulerUnits = startRulerUnits;
	app.preferences.typeUnits = startTypeUnits;
	this.parent.parent.close();
}

win.center();
win.show();


你可能感兴趣的:(photoshop)