Copy from Clipboard and paste

Anyone, especially newbies, asking for help with Photoshop Scripting and Photoshop Automation - as opposed to those contributing to discussion about an aspect of Photoshop Scripting

Moderators: Tom, Kukurykus

Peter-1
Posts: 1
Joined: Thu Sep 22, 2016 10:58 am

Copy from Clipboard and paste

Post by Peter-1 »

Hello everybody.
I have a complicated question, I do not know if it will be possible to resolve
Every day, I do various compositions with many photographs. this pictures have the present date.
So, through a .batch, the date is captured, to clipboard
when I make the script, I saw this line ( desc665.putString( idTxt, """22/09/2016 \r """ );) ).
So every time I run script always the date is ( 22/09/2016 ).
It could solve the problem


Thanks for helping

Professional AI Audio Generation within Adobe Premiere Pro - Download Free Plugin here

JavierAroche
Posts: 29
Joined: Sat Jul 30, 2016 3:52 am
Location: San Francisco

Re: Copy from Clipboard and paste

Post by JavierAroche »

Hey Peter, it would help if you could post your code so we can understand what you're trying to achieve.

It sounds like you need to make that date string into a variable that will reflect the current date. If that's the case, then you don't need to copy anything from your clipboard.

The function new Date() will give you the current date and time. You can then parse the date with a simple function to get the string you need and use it in your descriptor.

Code: Select all


var today = getFormattedDate(new Date());
// --> 10/29/2016

// Use the variable in your code
desc665.putString( idTxt, today );

// http://stackoverflow.com/questions/11591854/format-date-to-mm-dd-yyyy-in-javascript
function getFormattedDate(date) {
var year = date.getFullYear();
var month = (1 + date.getMonth()).toString();
month = month.length > 1 ? month : '0' + month;
var day = date.getDate().toString();
day = day.length > 1 ? day : '0' + day;
return month + '/' + day + '/' + year;
}
xbytor
Posts: 22
Joined: Thu Jan 01, 1970 12:00 am

Re: Copy from Clipboard and paste

Post by xbytor »

If you want to format dates, here's the code for you from xtools.

//========================= Date formatting ================================
//
// Date.strftime
// This is a third generation implementation. This is a JavaScript
// implementation of C the library function 'strftime'. It supports all
// format specifiers except U, W, z, Z, G, g, O, E, and V.
// For a full description of this function, go here:
// http://www.opengroup.org/onlinepubs/007 ... ftime.html
// Donating implementations can be found here:
// http://redhanded.hobix.com/inspect/show ... tTime.html
// and here:
// http://wiki.osafoundation.org/bin/view/ ... ptStrftime
//
// Object Method
Date.prototype.strftime = function (fmt) {
return Date.strftime(this, fmt);
};

// Class Function
Date.strftime = function(date, fmt) {
var t = date;
var cnvts = Date.prototype.strftime._cnvt;
var str = fmt;
var m;
var rex = /([^%]*)%([%aAbBcCdDehHIjmMprRStTuwxXyYZ]{1})(.*)/;

var result = '';
while (m = rex.exec(str)) {
var pre = m[1];
var typ = m[2];
var post = m[3];
result += pre + cnvts[typ](t);
str = post;
}
result += str;
return result;
};

// some ISO8601 formats
Date.strftime.iso8601_date = "%Y-%m-%d";
Date.strftime.iso8601_full = "%Y-%m-%dT%H:%M:%S";
Date.strftime.iso8601 = "%Y-%m-%d %H:%M:%S";
Date.strftime.iso8601_time = "%H:%M:%S";

Date.prototype.toISO = function() {
return this.strftime(Date.strftime.iso8601);
};


// the specifier conversion function table
Date.prototype.strftime._cnvt = {
zeropad: function( n ){ return n>9 ? n : '0'+n; },
spacepad: function( n ){ return n>9 ? n : ' '+n; },
ytd: function(t) {
var first = new Date(t.getFullYear(), 0, 1).getTime();
var diff = t.getTime() - first;
return parseInt(((((diff/1000)/60)/60)/24))+1;
},
a: function(t) {
return ['Sun','Mon','Tue','Wed','Thu','Fri','Sat'][t.getDay()];
},
A: function(t) {
return ['Sunday','Monday','Tuesdsay','Wednesday','Thursday','Friday',
'Saturday'][t.getDay()];
},
b: function(t) {
return ['Jan','Feb','Mar','Apr','May','Jun', 'Jul','Aug','Sep','Oct',
'Nov','Dec'][t.getMonth()]; },
B: function(t) {
return ['January','February','March','April','May','June', 'July','August',
'September','October','November','December'][t.getMonth()]; },
c: function(t) {
return (this.a(t) + ' ' + this.b(t) + ' ' + this.e(t) + ' ' +
this.H(t) + ':' + this.M(t) + ':' + this.S(t) + ' ' + this.Y(t));
},
C: function(t) { return this.Y(t).slice(0, 2); },
d: function(t) { return this.zeropad(t.getDate()); },
D: function(t) { return this.m(t) + '/' + this.d(t) + '/' + this.y(t); },
e: function(t) { return this.spacepad(t.getDate()); },
// E: function(t) { return '-' },
F: function(t) { return this.Y(t) + '-' + this.m(t) + '-' + this.d(t); },
g: function(t) { return '-'; },
G: function(t) { return '-'; },
h: function(t) { return this.b(t); },
H: function(t) { return this.zeropad(t.getHours()); },
I: function(t) {
var s = this.zeropad((t.getHours() + 12) % 12);
return (s == "00") ? "12" : s;
},
j: function(t) { return this.ytd(t); },
k: function(t) { return this.spacepad(t.getHours()); },
l: function(t) {
var s = this.spacepad((t.getHours() + 12) % 12);
return (s == " 0") ? "12" : s;
},
m: function(t) { return this.zeropad(t.getMonth()+1); }, // month-1
M: function(t) { return this.zeropad(t.getMinutes()); },
n: function(t) { return '\n'; },
// O: function(t) { return '-' },
p: function(t) { return this.H(t) < 12 ? 'AM' : 'PM'; },
r: function(t) {
return this.I(t) + ':' + this.M(t) + ':' + this.S(t) + ' ' + this.p(t);
},
R: function(t) { return this.H(t) + ':' + this.M(t); },
S: function(t) { return this.zeropad(t.getSeconds()); },
t: function(t) { return '\t'; },
T: function(t) {
return this.H(t) + ':' + this.M(t) + ':' + this.S(t) + ' ' + this.p(t);
},
u: function(t) {return t.getDay() ? t.getDay()+1 : 7; },
U: function(t) { return '-'; },
w: function(t) { return t.getDay(); }, // 0..6 == sun..sat
W: function(t) { return '-'; }, // not available
x: function(t) { return this.D(t); },
X: function(t) { return this.T(t); },
y: function(t) { return this.zeropad(this.Y(t) % 100); },
Y: function(t) { return t.getFullYear().toString(); },
z: function(t) { return ''; },
Z: function(t) { return ''; },
'%': function(t) { return '%'; }
};