Running SetAttr META commands from VBScript

I am trying to write a Vb script that will take the tags (keywords) from a file and copy them into a back-up of the file in a different. directory

I have gathered together the keywords in a variable and the name of the file I want to copy to another variable.

The problem comes when I add the instruction to do the actual copy

 	    ClickData.Func.Command.AddLine("SetAttr META newfilename ""tags:" & tagString & """")

newfilename is the name and path of the file I want to write the tags to, and tagString contains the keywords I want to write. They are filled with the correct information

It does not work. I suspect perhaps that because the variable newfilename contains spaces.

Try as I might - and I have tried - I can't find where to put the quote marks to make the command work.

Can one of you VB guru's help?

That code will literally insert "newfilename" into the command. If you want to insert the contents of the variable newfilename then you have to do the same thing you're doing with the tagString variable:

ClickData.Func.Command.AddLine("SetAttr META " & newfilename & " ""tags:" & tagString & """")

You'll also want to put quotes around it, which gives us this:

ClickData.Func.Command.AddLine("SetAttr META """ & newfilename & """ ""tags:" & tagString & """")

If you still have problems, run this line in the same place and see what it outputs to the script log:

DOpus.Output "SetAttr META """ & newfilename & """ ""tags:" & tagString & """"

First of all congratulations on the new look Resource Centre - a first rate job.

Leo - I see where I have gone wrong with the syntax here, but the problem is that even when I correct it the script does not work. It fails to write the keywords to the new file.

The first suspect,of course, is that I somehow constructed the path to the new file wrongly. I took that out of the equation by copying the file to the top of a drive. It still does not work even though your debug code seems to indicate it should

Function OnClick(ByRef clickData)
   If clickData.func.sourcetab.selected_files.count = 0 Then
      Msgbox "Nothing is selected",1, "NO FILE SELECTED"
	  End If
'Get the filenames of the selected files and construct the filename of the image to copy the keywords to	  
ClipString = ""
   For Each SelectedItem In ClickData.Func.sourcetab.Selected
         ClipString = SelectedItem.name_stem
		 exto = SelectedItem.ext
		 pathbo = selectedItem.path & "\" & ClipString & exto
		 oldpath = SelectedItem.path & "\"
		 'newfilename = "E:\Imaging\Working Images\Masks\" & clipstring & ".psd"
		 newfilename = "D:\" & clipstring & ".psd"
'Now get the tags in the source image into a variable   
   	     Dim q
      Set q = clickData.func.sourcetab.selected_files(0)
For Each tag In q.metadata.tags
            If (tagString <> "") Then
               tagString = tagString & "; "
               tagString = tagString & tag
                tagString = tag
            End If	
        DOpus.Output "SetAttr META """ & newfilename & """ ""tags:" & tagString & """"

'Now create the Opus command to copy the tags to the image
cmdline = "SetAttr META """ & newfilename & """ ""tags:" & tagString & """"
End Function

The output from your debug code gives me:

SetAttr META "D:\St Lukes 1970.psd" "tags:testpic;church"

Have you any idea why this might not work. I did wonder if it was in some way related to a problem I reported last week about problems I am having with keywords applied in Dopus not appearing in Photoshop CC 2017. (In fact that is the reason for t he script, so that I can restore the keywords from a backup file.) I can't see how, but you never know.

If you run that command manually, from a normal non-script button, does it work?

Ignoring Photoshop, can you see the changed tags in Opus? (If not, does changing the tags via the metadata panel work on the same file?)

No, Leo. The command does not insert the tags into the file when I run it from a button. I am not sure I understand the second part of your reply. But I can change to tags on the file using the Opus metadata panel quite successfully.

If you see my post on Tags not seen in Photoshop 2017 in the forum you will see the more serious side of the problem I am having

1 Like

This tell us the command itself is wrong, and not some other detail of the script.

We know where to focus now. Looking at the command in detail:

SetAttr META "D:\St Lukes 1970.psd" "tags:testpic;church"

You're passing the filepath to the META argument, which doesn't make sense. Try this instead:

SetAttr FILE "D:\St Lukes 1970.psd" META "tags:testpic;church"

This will also work (as long as the filepath comes before "META" (or any similar arguments), since "FILE" is the command's default argument):

SetAttr "D:\St Lukes 1970.psd" META "tags:testpic;church"

I'm aware of the other thread, but it's not directly relevant to this question.

Many thanks for your help. Works a treat