Help with updating file properties before renaming them

The following script will do that for any selected image files. Probably the easiest way for you to use this is to set up a new button that you use before embarking on a rename session. Select the images, click the script button to set the descriptions, and then rename them as a separate step.

[ul][li]To set up a button, go to Settings / Customize, then right-click on an empty area of a toolbar and choose New / New Button.[/li]
[li]Double-click the new button to edit it.[/li]
[li]Give it a name and choose an icon if desired.[/li]
[li]Click the Advanced button to enter Advanced mode in the command editor.[/li]
[li]Set the Function drop-down to Script Function.[/li]
[li]On the Script Code tab, set the Script Type drop-down to VBScript.[/li]
[li]Paste the below code into the script editor.[/li][/ul]

Option Explicit Function OnClick(ByRef clickData) Dim file, files Set files = clickData.func.sourcetab.selected_files For Each file in files Dim meta Set meta = file.metadata if meta = "image" Then Dim desc desc = "Original Values - Name: " & file.name desc = desc & ", Created: " & file.create desc = desc & ", Modified: " & file.modify desc = desc & ", Date Taken: " & meta.image.datetaken clickData.func.command.ClearFiles clickData.func.command.AddFile file clickData.func.command.RunCommand "SetAttr DESCRIPTION """ & desc & """" end if Next End Function

Thanks jon!

The script works as expected and I was even able to change something (super exciting!) to also write to tags .

clickData.func.command.RunCommand "SetAttr META ""Comment:" & desc & """" clickData.func.command.RunCommand "SetAttr META ""tags:" & desc & """"

However, tags and description both only write to image files (like you said they would). But is there a way to be able to add tags to any files since all should also have that property (I understand that the Date Taken will not be written to those)?

Also, if I want to make changes to multiple tabs, is the above correct way of doing it or should it optimized in one line somehow? I tried below but that does NOT work at al (maybe I'm just confused with all the quotes) :frowning:

'clickData.func.command.RunCommand "SetAttr META ""tags:" & desc & """Comments:" & desc & """"

Thanks again!

Oh duh, I obviously missed the If statement saying if meta = image. Just commenting it out made the code work for all files. This is actually pretty cool because I can use it to set different attributes to different file META section/file type!

So still the question of whether it's better to group SetAttr commands in on one line.

Grouping them on one line would be more efficient, yes.

Still have a lot to learn, but trying to do some basics here and getting the following error:

What I'm doing is adding the Format for the three dates. Adding it to the first two dates works fine, but when I add Format("D#yyyyMMdd_T#HHmmss") to the end of image.datetaken, I get the above error.

desc = desc & ", Created: " & file.create.Format("D#yyyyMMdd_T#HHmmss") desc = desc & ", Modified: " & file.modify.Format("D#yyyyMMdd_T#HHmmss") desc = desc & ", Date Taken: " & meta.image.datetaken

Any ideas here?

Looks like the file in question is not an image recognized by DO, so "meta.image" is not a valid object from which you could fetch the "datetaken" property.

tbone, the following "meta.image.datetaken" work fine on the image file im working on, but it comes out in this format: 8/20/2016 3:02:10 PM

Same default format comes out of create and modify, but after I add Format("D#yyyyMMdd_T#HHmmss") to the end of those two, the formats come out the new way. When I add the format to the end of datetaken "meta.image.datetaken.Format("D#yyyyMMdd_T#HHmmss")", it gives me the error even when working on image file.

It seems metadata.image.datetaken is different to item.create/modify. To me this looks like a bug or something Leo/Jon are able to equalize.
You can help yourself by creating a new DO-Date object from the string or whatever it is in metadata.image.datetaken.

		DOpus.Output("Create = " + typeof sel(i).create);
		DOpus.Output("Taken1 = " + typeof sel(i).metadata.image.datetaken);
		DOpus.Output("Taken2 = " + DOpus.Create.Date(sel(i).metadata.image.datetaken));
//outputs
Create = object
Taken1 = date
Taken2 = Thu Oct 13 16:20:18 UTC+0200 2016
Create = object
Taken1 = date
Taken2 = Thu Oct 13 16:22:48 UTC+0200 2016

Thanks tbone for helping here. After me spending a few days trying to use that in some way in the code provided by jon, I just can't figure out where to plug that in there not to get an error, and still how to change the date output format. I think my biggest confusion is still with the three different code types that can't be combined (JScript, VBscript, and Standard Function (Opus or external)). Also, some code is built to use in a button and some is to be used in the Rename interface via the script setting (which I prefer to use because it allows previews). To add to that, when testing the code via button, every iteration of change requires me to open the customize option, right click on button, edit code, close customize mode and test code... then open customize mode, edit button, close customize mode and test again. Is there a quick option for testing code on files quicker?

Go to Preferences/Toolbars/Options and check "Alt-Click to..."

In Opus 12 there is also a Run button, bottom left of the button editor, which lets you test without leaving Customize mode.

(Still a good idea to click OK and save the script every so often, in case anything goes wrong, if you have made big changes.)

Awesome, both suggestions work great with each other. Now it will make it a bit easier to go about hacking at everyone's codes here to see what sticks :slight_smile:

Okay! After a long weekend, I think I got it to work exactly as needed (without the renaming part for now).

It was annoying that I could not use the standard function "Format("D#yyyyMMdd_T#HHmmss")" on the meta data (still don't understand why it works on modified date but not on Date Taken), so I tried replacing the dates via regex but it was not possible to do with converting am to 24 hour time. So I found out that you can pull the different date parts from the using something else. So I took apart the date taken date into 6 parts and put it back together. It looks long and clumsy now but it works fine.

Thanks jon for the starting code and everyone else for their input. here is how it looks now:

[code]Option Explicit
Function OnClick(ByRef clickData)

' Current Timestamp function to format YYYYMMDDHHMMSS
Dim timeStamp, timeStamp24Year, timeStamp24Month, timeStamp24Day, timeStamp24Hour, timeStamp24Minute, timeStamp24Second, timeStampFormatted
timeStamp = now()
timeStamp24Year = (Year(timeStamp))
timeStamp24Month = (Month(timeStamp))
If (timeStamp24Month < 10) Then
timeStamp24Month = "0" & timeStamp24Month
End If
timeStamp24Day = (Day(timeStamp))
If (timeStamp24Day < 10) Then
timeStamp24Day = "0" & timeStamp24Day
End If
timeStamp24Hour = (Hour(timeStamp))
If (timeStamp24Hour < 10) Then
timeStamp24Hour = "0" & timeStamp24Hour
End If
timeStamp24Minute = (Minute(timeStamp))
If (timeStamp24Minute < 10) Then
timeStamp24Minute = "0" & timeStamp24Minute
End If
timeStamp24Second = (Second(timeStamp))
If (timeStamp24Second < 10) Then
timeStamp24Second = "0" & timeStamp24Second
End If
timeStampFormatted = timeStamp24Year & timeStamp24Month & timeStamp24Day & timeStamp24Hour & timeStamp24Minute & timeStamp24Second

' Selected files
Dim file, files
Set files = clickData.func.sourcetab.selected_files
For Each file in files
Dim fileName, createdDate, modifiedDate
fileName = file.name
createdDate = file.create.Format("D#yyyyMMdd_T#HHmmss")
modifiedDate = file.modify.Format("D#yyyyMMdd_T#HHmmss")
Dim desc, tag
desc = timeStampFormatted & " - not image file"
tag = "recorded on " & timeStampFormatted & " - name: " & fileName & ", created: " & createdDate & " , modified: " & modifiedDate

' If image file
if file.metadata = "image" Then
Dim imgTaken, imgTaken24Year, imgTaken24Month, imgTaken24Day, imgTaken24Hour, imgTaken24Minute, imgTaken24Second, imgTakenFormated
imgTaken = file.metadata.image.datetaken
imgTaken24Year = (Year(imgTaken))
imgTaken24Month = (Month(imgTaken))
If (imgTaken24Month < 10) Then
imgTaken24Month = "0" & imgTaken24Month
End If
imgTaken24Day = (Day(imgTaken))
If (imgTaken24Day < 10) Then
imgTaken24Day = "0" & imgTaken24Day
End If
imgTaken24Hour = (Hour(imgTaken))
If (imgTaken24Hour < 10) Then
imgTaken24Hour = "0" & imgTaken24Hour
End If
imgTaken24Minute = (Minute(imgTaken))
If (imgTaken24Minute < 10) Then
imgTaken24Minute = "0" & imgTaken24Minute
End If
imgTaken24Second = (Second(imgTaken))
If (imgTaken24Second < 10) Then
imgTaken24Second = "0" & imgTaken24Second
End If
imgTakenFormated = imgTaken24Year & imgTaken24Month & imgTaken24Day & "_" & imgTaken24Hour & imgTaken24Minute &imgTaken24Second
desc = timeStampFormatted & " - image file"
tag = "recorded on " & timeStampFormatted & " - name: " & fileName & ", created: " & createdDate & " , modified: " & modifiedDate & " , taken: " & imgTakenFormated
end if

     clickData.func.command.ClearFiles
     clickData.func.command.AddFile file
	 clickData.func.command.RunCommand "SetAttr META ""comment:" & desc & """"
	 clickData.func.command.RunCommand "SetAttr META ""tags: +" & +tag & """"

Next
End Function
[/code]

Although it works now, it was really fun working on it and looking to make some improvements. Mainly, I'm sure there must be a way to reuse the part where I broke up a date variable into 6 parts and put it back together. I think I may need to learn how to make a function out of that so that I can do something like "(someDate.myformatFunction(yyyyMMdd_HHmmss)" in the future if I want to format other date fields. So if anyone has any feedback on that or other comments about jiant mistakes I made above, please let me know.

Thanks!!

Anyone know how to view/print the file type (Movie, Image, Doc..) of the selected file using VBscript?

The groups property of an item object might be what you are looking for.

Regarding your date splitting and joining it back together, what I was saying in my post above was, that you probably can get around this by:

dim formattedDate : formattedDate = DOpus.Create.Date( file.metadata.image.datetaken ).Format("D#yyyyMMdd_T#HHmmss")

You wrap the unexpected date in file.metadata.image.datetaken in a call to DOpus.Create.Date, so that it gets converted from string or whatever it is into an actual DO Date object, on which you can run Format() as you would expect.

I am curious what Leo's and Jon's opinion is here, is it intentional that metadata.image.datetaken is different to item.modify/created?

No, it's an oversight. We'll fix it in a future version.

Wunderbar! o)

Thanks! DOpus.Create.Date works perfectly with Date Taken and with the date().

For the groups though, I'm still having some trouble getting it to work. I tried multiple combinations below and all give error: "Object does not support this property or method"

fileGroup = file.groups fileGroup = file.FiletypeGroup dim fileGroup : fileGroup = DOpus.Create.FiletypeGroup( file)

Did you look up the Item script object in the manual? You will find the name and type of the property I was referring to.
It's a vector, so you need to loop on it to get the actual group names, this is a quick jscript version, you get the idea I hope.

for(var i=0;i<item.groups.length;i++){ var groupName = ""+item.groups(i).display_name; }

Thanks tbone. I did read the manual portion before but I was trying stupid combination with it, like:
DOpusFactory.Vector.FiletypeGroup(FileName). But it turns out I don't really need this last part so not going to waste anyones time on it. Thanks again all for your help.