Guest User

Photoshop-Skript

a guest
Feb 22nd, 2020
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function process() {
  2.   var origDoc = activeDocument;
  3.   var fullName = origDoc.name;
  4.  
  5.   if (!prefs.incExt) {
  6.     fullName = fullName.replace(/(?:.[^.]$|$)/, '');
  7.   }
  8.  
  9.   if (prefs.incPath) {
  10.     fullName = origDoc.path.toString() + " :: " + fullName;
  11.   }
  12.  
  13.   var myLayerRef = origDoc.artLayers.add();
  14.   myLayerRef.kind = LayerKind.TEXT;
  15.   myLayerRef.name = fullName;
  16.   var myTextRef = myLayerRef.textItem;
  17.   myTextRef.position = new Array(prefs.startOffsetFromLeft, origDoc.height - prefs.textFromBottom);
  18.   myTextRef.size = prefs.fontSize;
  19.   myTextRef.contents = myLayerRef.name;
  20. }
  21.  
  22. function main() {
  23.   try {
  24.     setOptions();
  25.     process();
  26.   }
  27.   catch (e) {
  28.     /* An error occurred. Restore ruler units, then propagate the error back to the user */
  29.     preferences.rulerUnits = prefs.originalRulerUnits;app.displayDialogs = prefs.originalDialogMode;
  30.     throw e;
  31.   }
  32. }
  33.  
  34. function setOptions() {
  35.   #target estoolkit
  36.   var win, windowResource;
  37.   windowResource = "dialog {
  38.    orientation: 'column',
  39.    alignChildren: ['fill', 'top'],
  40.    preferredSize: [350, 180],
  41.    text: 'Photoshop Script - Insert FileName (TextLayer)',
  42.    margins: 10,
  43.    settingPanel: Group {
  44.      orientation: 'column',
  45.      fontSize: Group {
  46.        st4: StaticText {
  47.          text: 'Select Font Size:'
  48.        },
  49.        sl: Slider {
  50.          minvalue: 10,
  51.          maxvalue: 50,
  52.          value: 25,
  53.          size: [200, 20]
  54.        },
  55.        quality: StaticText {
  56.          text: '25px',
  57.          characters: 4
  58.        }
  59.      },
  60.      incPath: Checkbox {
  61.        text: 'Include Path',
  62.        value: false
  63.      },
  64.      incExt: Checkbox {
  65.         text: 'Include Extension',
  66.        value: false
  67.       },
  68.       applyButton: Button {
  69.         text: 'Insert»',
  70.        properties: { name: 'ok' },
  71.        size: [350, 30],
  72.        weight: bold
  73.       },
  74.       dummy:StaticText { text: '' },
  75.       alignChildren: 'left',
  76.    }
  77.    creditGroup: Group {
  78.         orientation: 'row',
  79.      alignChildren: 'right',
  80.      linkText: StaticText {
  81.         text: 'Visit us: www.tejwani.com/photoshop-scripting/'
  82.      },
  83.    }
  84.     }"
  85.   win = new Window(windowResource);
  86.  
  87.   /* listen and update text box */
  88.   win.settingPanel.fontSize.sl.onChange = function() {
  89.     win.settingPanel.fontSize.quality.text = Math.round(this.value) + 'px';
  90.     }
  91.   /* apply button */
  92.   win.settingPanel.applyButton.onClick = function() {
  93.     prefs.fontSize = win.settingPanel.fontSize.quality.text;
  94.     prefs.incPath = win.settingPanel.incPath.value;
  95.     prefs.incExt = win.settingPanel.incExt.value;
  96.     return win.close();
  97.   };
  98.   win.creditGroup.linkText.onClick = function() {
  99.     File(app.path.toString() + "/Presets/Scripts/TS-insert-filename.html").execute();
  100.   };
  101.   win.show();  
  102. }
Add Comment
Please, Sign In to add comment