GP SoftwareTwitter
Opus FAQsManualCommandsObjects

SetAttr from Clipboard date

Hi,

I stuck with simple thing. I am sure you could help me to get trough.
I have a video file with (for example) such a name:
20150829201931.m2ts
As you can see - the name is in fact the date. I managed to change it (with external macro, which I have prepared earlier) for such a date in clipboard (of course as text):
2015-08-29 20:19:31

Now - how to use this clipboard content for SetAttr CREATED? (I wish to use it with button, not in a script)?

You can use {clip} to insert the clipboard text into a button. (Note: It will be the clipboard text as it was before any part of the button ran.)

You might be better off moving everything into a script, though. Then you don't have to modify your clipboard at all and you can do everything in a single action. A script that takes filenames like 20150829201931.* and runs the appropriate SetAttr command would be quite simple. Shout if you need help with how to write it.

Thanks, but not what I wanted, because the changed buffer comes after running script in the button.
If I can get the clipboard contents while doing the script under the button - it would do the job...

Could be fine, but I'd rather have a problem with variables and manipulating them in the script (I am not very experienced with vbs). If you could point me and example of similar script, I could try to rearrange it.

Here's the VBScript code:

[code]@script VBScript
Option Explicit
Function OnClick(ByRef clickData)
Dim re, fileItem, fileDate, cmdString

clickData.Func.command.deselect = False
clickData.Func.command.ClearFiles

Set re = new RegExp
re.Pattern = "^(\d\d\d\d)(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)(\.[^.]+)$"

For Each fileItem in clickData.Func.sourceTab.selected_files
	If (re.Test(fileItem.name)) Then
		fileDate = re.Replace(fileItem.name, "$1-$2-$3 $4:$5:$6")
		cmdString =  "SetAttr FILE=""" & fileItem.realpath & """ CREATED=""" & fileDate & """"
		clickData.Func.command.RunCommand cmdString
	End If
Next

End Function[/code]

Here's it is in XML button form, ready to paste on to a toolbar:

<?xml version="1.0"?> <button backcol="none" display="both" icon_size="large" label_pos="right" textcol="none"> <label>Set Date from Name</label> <icon1>#setdate</icon1> <function type="script"> <instruction>@script VBScript</instruction> <instruction>Option Explicit</instruction> <instruction>Function OnClick(ByRef clickData)</instruction> <instruction> Dim re, fileItem, fileDate, cmdString</instruction> <instruction /> <instruction> clickData.Func.command.deselect = False</instruction> <instruction> clickData.Func.command.ClearFiles</instruction> <instruction /> <instruction> Set re = new RegExp</instruction> <instruction> re.Pattern = &quot;^(\d\d\d\d)(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)(\.[^.]+)$&quot;</instruction> <instruction /> <instruction> For Each fileItem in clickData.Func.sourceTab.selected_files</instruction> <instruction> If (re.Test(fileItem.name)) Then</instruction> <instruction> fileDate = re.Replace(fileItem.name, &quot;$1-$2-$3 $4:$5:$6&quot;)</instruction> <instruction> cmdString = &quot;SetAttr FILE=&quot;&quot;&quot; &amp; fileItem.realpath &amp; &quot;&quot;&quot; CREATED=&quot;&quot;&quot; &amp; fileDate &amp; &quot;&quot;&quot;&quot;</instruction> <instruction> clickData.Func.command.RunCommand cmdString</instruction> <instruction> End If</instruction> <instruction> Next</instruction> <instruction /> <instruction>End Function</instruction> </function> </button>

Thank you Leo.
It works like a charm!
(It is simple when you know and quite difficult when you have to find each command - when not impossible :wink:

I have added two lines to have a date from EXIF (if exists) and modified the checking line so each file starting from 14 digits and ending whatever will have both dates changed.
Sony Play Memories puts both films and images in the same folder. Images regularly have proper dates, but films not (there is no Exif date to correct it). With this version one could set all dates at once if needed (regardless if picture or film).

[code]@script VBScript
Option Explicit
Function OnClick(ByRef clickData)
Dim re, fileItem, fileDate, cmdString

clickData.Func.command.deselect = False
clickData.Func.command.ClearFiles

Set re = new RegExp
re.Pattern = "^(\d\d\d\d)(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)(.+)$"

For Each fileItem in clickData.Func.sourceTab.selected_files
cmdString = "SetAttr FILE=""" & fileItem.realpath & """ SETATTR META createdate:datetaken lastmodifieddate:datetaken"""
clickData.Func.command.RunCommand cmdString
If (re.Test(fileItem.name)) Then
fileDate = re.Replace(fileItem.name, "$1-$2-$3 $4:$5:$6")
cmdString = "SetAttr FILE=""" & fileItem.realpath & """ CREATED=""" & fileDate & """, MODIFIED=""" & fileDate & """"
clickData.Func.command.RunCommand cmdString
End If
Next

End Function
[/code]