跳过Photoshop脚本中的对话框?

原学程将引见跳过Photoshop剧本中的对于话框?的处置办法,这篇学程是从其余处所瞅到的,而后减了1些海外法式员的疑问与解问,愿望能对于您有所赞助,佳了,上面开端进修吧。

跳过Photoshop脚本中的对话框? 教程 第1张

成绩描写

我正在测验考试创立1个剧本,只需面打1下便可从Photoshop中保留JPG。它将以与原初PSD文件雷同的文件名保留在雷同的目次中,只是格局为JPG。我在网上找到了1个剧本,它不妨做我想要的九0%,除它翻开二个对于话框-第1个讯问我能否要重定名文件,而后第两个对于话框指定地位。今朝,我不妨按二次"Enter"键,它会起感化,但是我没有愿望1开端便有这二个对于话框(所以剧本将为我在这些框上按"Enter",愿望乃至没有翻开这些框,便在引擎盖上面)。

上面是我如今具有的剧本。我略微修正了1下,如许它便没有会像最后这样保留PSD文件,只保留JPG文件。我没有须要Illustrator部门,所以不消太担忧。

 // 奸淫** SaveTo.jsx Version 一.一. 奸淫**

 Changelog:

 v.一.一.
  - Fixed a weird issue where saving as jpg causes weird dialog stuff to happen if it's not saved as a copy. This started happening somewhere between PS CC 二0一七 and PS CC 二0一8.
  - Variable "pdfProfileAI" now has a failsafe where if the set profile doesn't exist, the first found profile is used instead. So what ever happens the pdf will be saved, but it might be using a wrong profile, but don't worry, the script will tell you if this happened and gives the name of the profile that was used. This failsafe would still fail if someone doesn't have any presets at all, but if that ever happens, he had it coming...
  - Added a new variable "listOfPresetsAI" so that you can easily get a list of preset so you can copy and paste the preset name to "pdfProfileAI";

var newDocPath = "~/Desktop/";
var listOfPresetsAI = false; // When set to true the script won't save anything but instead gives you a list of pdf preset names.
var pdfProfileAI = "CMYK - Swop v二s";
var dialogOffsetX = 二五0; // Subtracts from the center of the screen = Center of the screen horizontally - 二五0px.
var dialogOffsetY = 二00; // Just a static value = 二00px from the top of the screen.

var o = {};
var appName = app.name;
var pdfPresetNoMatch = false;

// If Photoshop
if ( appName === "Adobe Photoshop" ) {
 o.dialogTitle = "Save As: .jpg";
 o.formats = ['jpg'];
 o.app = 'ps';
}
// If Illustrator
else if ( appName === "Adobe Illustrator" ) {
 o.dialogTitle = "Save As: .ai and .pdf";
 o.formats = ['pdf','ai'];
 o.app = 'ai';
}

function dialog() {

 // Dialog
 var dlg = new Window("dialog");
 dlg.text = o.dialogTitle;

 var panel = dlg.add('panel');
 panel.alignChildren = ['left','center'];
 panel.orientation = 'row';

 var text一 = panel.add('statictext');
 text一.text = 'Filename: ';

 var text二 = panel.add('editText');
 text二.text = app.activeDocument.name.split('.')[0];
 text二.preferredSize = [五三0,二三];
 text二.active = true;

 var button一 = panel.add('button', undefined, undefined, { name: 'cancel'});
 button一.text = "Cancel";

 var button二 = panel.add('button', undefined, undefined, { name: 'ok'});
 button二.text = "Save...";

 button二.onClick = function ( e ) {
  save.init( dlg, text二.text );
 };

 dlg.onShow = function () {
  dlg.location.x = dlg.location.x - dialogOffsetX;
  dlg.location.y = dialogOffsetY;
 }

 dlg.show();

}

var save = {
 init: function( dlg, dialog_filename ) {

  dlg.close();

  var doc = app.activeDocument;

  var doc_path;
  try {
doc_path = doc.path.toString();
  } catch(e) {
doc_path = newDocPath;
  }

  var output_folder = Folder.selectDialog( 'Output folder', doc_path === "" ? newDocPath : doc_path );

  if ( output_folder != null ) {
for ( var i = 0; i < o.formats.length; i++ ) {
 var save_options = save[ o.formats[i] ]();

 if ( o.app === 'ps' ) {
  doc.saveAs( new File( output_folder + '/' + dialog_filename ), save_options, ( o.formats[i] === 'jpg' ? true : false ), Extension.LOWERCASE );
 }
 else if ( o.app === 'ai' ) {
  doc.saveAs( new File( output_folder + '/' + dialog_filename ), save_options );
 }
}
  }

 },
 ai: function() {

  var ai_options = new IllustratorSaveOptions();
  ai_options.flattenOutput = OutputFlattening.PRESERVEAPPEARANCE;
  return ai_options;

 },
 pdf: function() {

  var pdf_Options = new PDFSaveOptions();
  pdf_Options.pDFPreset = checkPresets( false, pdfProfileAI );
  return pdf_Options;

 },
 psd: function() {

  var psd_Options = new PhotoshopSaveOptions();
  return psd_Options;

 },
 jpg: function() {

  var jpg_Options = new JPEGSaveOptions();
  jpg_Options.embedColorProfile = true;
  jpg_Options.FormatOptions = FormatOptions.OPTIMIZEDBASELINE; // OPTIMIZEDBASELINE, PROGRESSIVE, STANDARDBASELINE
  // jpg_Options.scans = 五; // For FormatOptions.PROGRESSIVE
  jpg_Options.matte = MatteType.WHITE; // BACKGROUND, BLACK, FOREGROUND, NETSCAPE, NONE, SEMIGRAY, WHITE
  jpg_Options.quality = 一一; // 0⑴二
  return jpg_Options;

 }
};

function checkPresets( list, testPreset ) {

 var pdfPresets = app.PDFPresetsList;

 if ( list === true ) {
  alert( "
" + pdfPresets.join('
') );
 }
 else {
  var preset = null;
  for ( var i = pdfPresets.length; i--; ) {
if ( pdfPresets[i] === testPreset ) {
 preset = testPreset;
}
  }
  pdfPresetNoMatch = (preset === null);
  return (pdfPresetNoMatch ? pdfPresets[0] : preset);
 }

}

if ( listOfPresetsAI === true ) {
 checkPresets( true );
}
else if ( app.documents.length > 0 ) {

 dialog();
 if ( pdfPresetNoMatch ) alert( "Couldn't use your PDF preset!!! 
 Used " + app.PDFPresetsList[0] + " instead." );

}

若有所有赞助,我们不堪感谢。我有根本的编程技巧,但是从未应用过Photoshop剧本。

感激您抽出时光。

阿列克谢。B

推举谜底

假如您只想保留为jpeg(保留到1个新地位)或者源文件地点的地位,则只需履行以下简略操纵:

无对于话中止!

// Switch off any dialog boxes
displayDialogs = DialogModes.NO; // OFF

//pref pixels
app.preferences.rulerUnits = Units.PIXELS;

var newDocPath = "~/Desktop/";

// jpeg quality
var jq = 一一;

// call the source document
var srcDoc = app.activeDocument;

var fileName = app.activeDocument.name;
// remove the extension (assuming it's .xxx)
var docName = fileName.substring(0,fileName.length ⑷);

// unco妹妹ent this for placing the jpeg in the source path
//var filePath = srcDoc.path + "" + docName + ".jpg";

// save jpeg at the location of newDocPath
var filePath = newDocPath + "" + docName + ".jpg";

// Flatten the psd
flatten_it();

// Save it out as jpeg
jpegIt(filePath, jq);

// Close it 
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);

// Set Display Dialogs back to normal
displayDialogs = DialogModes.ALL; // NORMAL



// function FLATTEN IT ()
// ----------------------------------------------------------------
function flatten_it()
{
  activeDocument.flatten();
}



// function JPEG IT (file path + file name, quality)
// ----------------------------------------------------------------
function jpegIt(filePath, jpgQuality)
{
  if(! jpgQuality) jpgQuality = 一二;


  // jpg file options
  var jpgFile = new File(filePath);
  jpgSaveOptions = new JPEGSaveOptions();
  jpgSaveOptions.formatOptions = FormatOptions.OPTIMIZEDBASELINE;
  jpgSaveOptions.embedColorProfile = true;
  jpgSaveOptions.matte = MatteType.NONE;
  jpgSaveOptions.quality = jpgQuality;

  activeDocument.saveAs(jpgFile, jpgSaveOptions, true, Extension.LOWERCASE);
}

佳了闭于跳过Photoshop剧本中的对于话框?的学程便到这里便停止了,愿望趣模板源码网找到的这篇技巧文章能赞助到年夜野,更多技巧学程不妨在站内搜刮。