Write Metadata Error.

Hi,
I have installed the exif package for macOS, and created the following code - which I want to write to the copyright meta tag in an image.

The code compiles, but no metadata gets written to the file (I checked the file’s modified date).
Can anyone tell from my code, where the error is?

[code]Dim jpegType As New FileType
jpegType.Name = “image/jpeg”
jpegType.MacType = “JPEG”
jpegType.MacCreator = “prvw”
jpegType.Extensions = “jpg;jpeg”

Dim pngType As New FileType
pngType.Name = “image/png”
pngType.MacType = "PNG "
pngType.MacCreator = “ogle”
pngType.Extensions = “png”

Dim dialog As OpenDialog
Dim file As FolderItem

dialog = New OpenDialog

dialog.PromptText = “Please Select Image”
dialog.Filter = jpegType + pngType
dialog.InitialDirectory=SpecialFolder.Applications.child(“DAM”)

file = dialog.ShowModalWithin(Self)

If file <> Nil Then
Dim SelectedFile As String = file.AbsolutePath
Else
Dim SelectedFile As String = “Cancelled”
End If

Dim sh as New Shell
sh.execute “exiftool -overwrite_original -copyright=‘myfirstname mysurname’ SelectedFile”
sh.close[/code]

After running this code, what’s the value of sh.result and sh.errorcode?

Oh duh… selectedFile should not be inside the quotes.

Use " + selectedFile

Thanks Greg - I will try that, and report back in a few minutes :slight_smile:

Oh, and dimming SelecredFile inside of the if statement limits their scope, so they won’t be valid when you need it.

Dim first and just assign in the if statement.

Thanks - I’ll try that.

This is my modified code:

[code]Dim jpegType As New FileType
jpegType.Name = “image/jpeg”
jpegType.MacType = “JPEG”
jpegType.MacCreator = “prvw”
jpegType.Extensions = “jpg;jpeg”

Dim pngType As New FileType
pngType.Name = “image/png”
pngType.MacType = "PNG "
pngType.MacCreator = “ogle”
pngType.Extensions = “png”

Dim dialog As OpenDialog
Dim file As FolderItem

dialog = New OpenDialog

dialog.PromptText = “Please Select Image”
dialog.Filter = jpegType + pngType
dialog.InitialDirectory=SpecialFolder.Applications.child(“DAM”)

file = dialog.ShowModalWithin(Self)

Dim SelectedFile As String

If file <> Nil Then
SelectedFile = file.AbsolutePath
Else
SelectedFile = “Cancelled”
End If

Dim sh as New Shell
sh.execute “exiftool -overwrite_original -copyright=‘myfirstname mysurname’” + SelectedFile.ShellPath
sh.close[/code]

I now get a compile error saying “The type string has no member named ShellPath”.

Modified my code again - still to no avail :frowning:

[code]Dim jpegType As New FileType
jpegType.Name = “image/jpeg”
jpegType.MacType = “JPEG”
jpegType.MacCreator = “prvw”
jpegType.Extensions = “jpg;jpeg”

Dim pngType As New FileType
pngType.Name = “image/png”
pngType.MacType = "PNG "
pngType.MacCreator = “ogle”
pngType.Extensions = “png”

Dim dialog As OpenDialog
Dim file As FolderItem

dialog = New OpenDialog

dialog.PromptText = “Please Select Image”
dialog.Filter = jpegType + pngType
dialog.InitialDirectory=SpecialFolder.Applications.child(“DAM”)

file = dialog.ShowModalWithin(Self)

Dim SelectedFile As String

If file <> Nil Then
SelectedFile = file.AbsolutePath

    Dim sh as New Shell
    sh.execute "exiftool -overwrite_original -copyright='myfirstname mysurname'" + SelectedFile.ShellPath
    sh.close

End If[/code]

SelectedFile is a STRING containing already AbsolutePath…

Not a FolderItem…

This is what I cannot understand.
I thought that my code below sets SelectedFile to the path of the selected image, but when I add +SelectedFile to the end of my command line, it compiles but does not do anything to the image file???

[code]Dim jpegType As New FileType
jpegType.Name = “image/jpeg”
jpegType.MacType = “JPEG”
jpegType.MacCreator = “prvw”
jpegType.Extensions = “jpg;jpeg”

Dim pngType As New FileType
pngType.Name = “image/png”
pngType.MacType = "PNG "
pngType.MacCreator = “ogle”
pngType.Extensions = “png”

Dim dialog As OpenDialog
Dim file As FolderItem

dialog = New OpenDialog

dialog.PromptText = “Please Select Image”
dialog.Filter = jpegType + pngType
dialog.InitialDirectory=SpecialFolder.Applications.child(“DAM”)

file = dialog.ShowModalWithin(Self)

Dim SelectedFile As String

If file <> Nil Then
SelectedFile = file.AbsolutePath

    Dim sh as New Shell
    sh.execute "exiftool -overwrite_original -copyright='myfirstname mysurname'" + SelectedFile
    sh.close

End If[/code]

You have to use ShellPath for shell commands, not AbsolutePath.
ShellPath and AbsolutePath are properties of FolderItem, so you won’t be able to use it on the SelectedFile string.

Change file.AbsolutePath to file.ShellPath and see if that helps.

Tim,
I tried what you said, but I get the same result - it compiles, but the image file does not get the meta data added.

Richard, I noticed before you have trouble understanding variable types.

You DIM SelectedFile as String, and later treat it as a FolderItem. That is your original error.

Moreover, drop once and for all AbsolutePath. Use ShellPath instead.

Tim told you what to do.

Michel,
I did do what Tim advised:

[code]Dim dialog As OpenDialog
Dim file As FolderItem

dialog = New OpenDialog

dialog.PromptText = “Please Select Image”
dialog.Filter = jpegType + pngType
dialog.InitialDirectory=SpecialFolder.Applications.child(“DAM”)

file = dialog.ShowModalWithin(Self)

Dim SelectedFile As String

If file <> Nil Then

SelectedFile = file.ShellPath

Dim sh as New Shell
sh.execute “exiftool -overwrite_original -copyright=‘Richard Summers’” + SelectedFile
sh.close

End If[/code]

And with all due respect, not everyone is a natural developer, and some of us have trouble understanding certain concepts.

I probably use Xojo for one or two days a year, therefore, when someone says “The Language Reference is your Friend”, it often does not help in the slightest if you cannot understand the LR.

My understanding of my code is:
SelectedFile is a string, and that string obtains the shell path of the chosen file (as a string). I am then using + SelectedFile in my command line, to set the file to be worked on.

Therefore I cannot work out where my error is.

Good luck.

Richard you should try setting up your shell execute line in a string so you can debug it.
You can pause execution, copy the string variable contents to the clipboard, and attempt the shell command in Terminal.

You may be missing a space after setting the copyright option and before the file path.

Hi Richard,

I tried your code and there seems to be a problem in this line

dialog.Filter = jpegType + pngType

I used dialog.Filter = “.jpeg” instead and it compiles.

What des this code do? I do not see anything happening to the image.

Lennox

When I edit the code like this…
sh.execute “exiftool -overwrite_original -copyright=‘Richard Summers’” + SelectedFile

If sh.errorCode = 0 then
  msgbox "No error"
  
else
  msgbox "Error " + Str(sh.ErrorCode)
  
end if

sh.close

I get error 127

Value 127 is returned by /bin/sh when the given command is not found within your PATH system variable and it is not a built-in shell command. In other words, the system doesn’t understand your command, because it doesn’t know where to find the binary you’re trying to call.

http://stackoverflow.com/questions/1763156/127-return-code-from

looks like you are missing a SPACE before the double quote preceding your + selectedfile