Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function process() {
- var origDoc = activeDocument;
- var fullName = origDoc.name;
- if (!prefs.incExt) {
- fullName = fullName.replace(/(?:.[^.]$|$)/, '');
- }
- if (prefs.incPath) {
- fullName = origDoc.path.toString() + " :: " + fullName;
- }
- var myLayerRef = origDoc.artLayers.add();
- myLayerRef.kind = LayerKind.TEXT;
- myLayerRef.name = fullName;
- var myTextRef = myLayerRef.textItem;
- myTextRef.position = new Array(prefs.startOffsetFromLeft, origDoc.height - prefs.textFromBottom);
- myTextRef.size = prefs.fontSize;
- myTextRef.contents = myLayerRef.name;
- }
- function main() {
- try {
- setOptions();
- process();
- }
- catch (e) {
- /* An error occurred. Restore ruler units, then propagate the error back to the user */
- preferences.rulerUnits = prefs.originalRulerUnits;app.displayDialogs = prefs.originalDialogMode;
- throw e;
- }
- }
- function setOptions() {
- #target estoolkit
- var win, windowResource;
- windowResource = "dialog {
- orientation: 'column',
- alignChildren: ['fill', 'top'],
- preferredSize: [350, 180],
- text: 'Photoshop Script - Insert FileName (TextLayer)',
- margins: 10,
- settingPanel: Group {
- orientation: 'column',
- fontSize: Group {
- st4: StaticText {
- text: 'Select Font Size:'
- },
- sl: Slider {
- minvalue: 10,
- maxvalue: 50,
- value: 25,
- size: [200, 20]
- },
- quality: StaticText {
- text: '25px',
- characters: 4
- }
- },
- incPath: Checkbox {
- text: 'Include Path',
- value: false
- },
- incExt: Checkbox {
- text: 'Include Extension',
- value: false
- },
- applyButton: Button {
- text: 'Insert»',
- properties: { name: 'ok' },
- size: [350, 30],
- weight: bold
- },
- dummy:StaticText { text: '' },
- alignChildren: 'left',
- }
- creditGroup: Group {
- orientation: 'row',
- alignChildren: 'right',
- linkText: StaticText {
- text: 'Visit us: www.tejwani.com/photoshop-scripting/'
- },
- }
- }"
- win = new Window(windowResource);
- /* listen and update text box */
- win.settingPanel.fontSize.sl.onChange = function() {
- win.settingPanel.fontSize.quality.text = Math.round(this.value) + 'px';
- }
- /* apply button */
- win.settingPanel.applyButton.onClick = function() {
- prefs.fontSize = win.settingPanel.fontSize.quality.text;
- prefs.incPath = win.settingPanel.incPath.value;
- prefs.incExt = win.settingPanel.incExt.value;
- return win.close();
- };
- win.creditGroup.linkText.onClick = function() {
- File(app.path.toString() + "/Presets/Scripts/TS-insert-filename.html").execute();
- };
- win.show();
- }
Add Comment
Please, Sign In to add comment