/* ==========================================================
// 2013 John J. McAssey (JJMack)
// ======================================================= */
// This script is supplied as is. It is provided as freeware.
// The author accepts no liability for any problems arising from its use.
// I set a shortcut key in my case F5 to this Photoshop script mainly for doing Window screen capturing of:
// desktop displays, Active window and selected area copy to clipboard. The script log the cardboard into a document with the name clipboard.
/*
<javascriptresource>
<about>$$$/JavaScripts/PasteClipboard/About=JJMack's Paste Clipboard into Clipboard document.^r^rCopyright 2014 Mouseprints.^r^rJJMack's Script.^r
NOTE:New Clipboard Document will be open if necessary</about>
<category>JJMack's Script</category>
</javascriptresource>
*/
// enable double-clicking from Mac Finder or Windows Explorer
#target photoshop // this command only works in Photoshop CS2 and higher
// bring application forward for double-click events
app.bringToFront();
if (!documents.length) {
NewCliboardDoc ();
app.activeDocument.suspendHistory('pasteClipboard','main(true)'); // New document opened proceed
}
else { //locate Document clipboard
for (var i=0;i<app.documents.length;i++) {
app.activeDocument=app.documents;
if (app.activeDocument.name == "Clipboard"){break;}
}
if (app.activeDocument.name != "Clipboard"){
NewCliboardDoc ();
app.activeDocument.suspendHistory('pasteClipboard','main(true)'); // New document opened proceed
}
else {app.activeDocument.suspendHistory('pasteClipboard','main(false)'); } // Old Clipboard Document found
}
///////////////////////////////////////////////////////////////////////////////
// main function //
///////////////////////////////////////////////////////////////////////////////
function main(newFile) {
// declare local variables
var orig_ruler_units = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS; // Set the ruler units to PIXELS
try {
activeDocument.paste(); // past in clipboard may fail enclose in try
var LB = app.activeDocument.activeLayer.bounds; // Get the bounds of the work layer
var LWidth = (LB[2].value) - (LB[0].value); // Area width
var LHeight = (LB[3].value) - (LB[1].value); // Area height
// BOTTOMCENTER BOTTOMLEFT BOTTOMRIGHT MIDDLECENTER MIDDLELEFT MIDDLERIGHT TOPCENTER TOPLEFT TOPRIGHT
if(newFile) {
app.activeDocument.resizeCanvas(LWidth, LHeight, AnchorPosition.TOPLEFT);
app.activeDocument.layers[1].remove();
}
app.activeDocument.selection.selectAll(); // select all
// Left('AdLf'); Right('AdRg'); Top('AdTp'); Bottom('AdBt'); Center Horizontal('AdCH'); Center Vertical('AdCV');
align("AdCH");align("AdBt"); //Align to selection center bottom
app.activeDocument.selection.deselect();
SetViewFitonScreen();
}
catch(e) {
if(newFile) app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
alert("Clipboard Empty");
}
app.preferences.rulerUnits = orig_ruler_units; // Reset units to original settings
}
///////////////////////////////////////////////////////////////////////////////
// main function end //
///////////////////////////////////////////////////////////////////////////////
function NewCliboardDoc () {
// app.documents.add([width][, height][, resolution][, name][, mode][, initialFill][, pixelAspectRatio][, bitsPerChannel][, colorProfileName])
var Clipboard = app.documents.add( null, null, 100, "Clipboard", NewDocumentMode.RGB, null, null, null, "sRGB IEC61966-2.1");
}
function align(method) {
var desc = new ActionDescriptor();
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID( "Lyr " ), charIDToTypeID( "Ordn" ), charIDToTypeID( "Trgt" ) );
desc.putReference( charIDToTypeID( "null" ), ref );
desc.putEnumerated( charIDToTypeID( "Usng" ), charIDToTypeID( "ADSt" ), charIDToTypeID( method ) );
executeAction( charIDToTypeID( "Algn" ), desc, DialogModes.NO );
};
function SetViewFitonScreen() {
var desc1 = new ActionDescriptor();
var ref1 = new ActionReference();
ref1.putEnumerated(charIDToTypeID('Mn '), charIDToTypeID('MnIt'), charIDToTypeID('FtOn'));
desc1.putReference(charIDToTypeID('null'), ref1);
executeAction(charIDToTypeID('slct'), desc1, DialogModes.NO);
};