• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Using arbitrary Unicode characters with LrTasks.execute() and ExifTool

LEGEND ,
Jul 10, 2017 Jul 10, 2017

Copy link to clipboard

Copied

This note records what I've learned about using arbitrary Unicode characters in commands executed by LrTasks.execute(), especially ExifTool.

On Mac:

All Unicode characters in command lines and scripts work just fine -- you don't have to do anything special. This includes invoking ExifTool.

On Windows:

Extra care is needed.  All Unicode characters in the command line passed to LrTasks.execute() will be properly interpreted by the command interpreter "cmd.exe".

However, if your plugin runs a batch file to be executed by LrTasks.execute() (which invokes "cmd.exe"), and the batch file contains arbitrary Unicode characters, you'll need to save the batch file encoded in UTF-8 and put the following command at the top of the batch file:

chcp 65001

This tells the "cmd.exe" to interpret the rest of the batch file as UTF-8.  By default, "cmd.exe" interprets batch files as being in the character encoding specified by operating-system wide character set ("code page").  In North America and much of Europe, that's usually Latin 1 by default.   Note that if any files written by LR will be in UTF-8, so if you're plugin writes a batch file, it will automatically be in UTF-8.

ExifTool on Windows:

If you're invoking ExifTool directly from LrTasks.execute() or from a batch file, then beware that there is no way to pass arbitrary Unicode characters on the command line to ExifTool.  You need to write such arguments to an arg file:

exiftool -@ myargs.txt

Also beware that if you construct the arg file in LrPathUtils.getStandardFilePath ("temp"), the temp directory will be in the user's home directory, and if the username contains arbitrary Unicode characters, you won't be able to pass the full path on the command line to ExifTool.  The workaround is to "cd" to the temp directory, e.g.

D: & cd "\Users\jóȟň\AppData\Local\Temp" & exiftool -@ myargs.txt

(Note you first have to change the current volume, then "cd" t change the current directory on that volume.  DOS lives. You might be tempted to use "pushd" instead, but "pushd" assigns a new drive letter, which triggers LR to open the Import window!)

If the path to the arg file is a UNC path (starting with "\\") and contains Unicode characters not in the current operating-system character set (e.g. Latin1), then you're out of luck -- you can't "cd" to a UNC path in "cmd.exe", and you can't use "pushd", since that will cause LR to open the Import window.  You'll have write the arg file to some directory on a volume named by a drive letter, or perhaps see if Powershell or another shell can be used instead.  (But LR will always invoke "cmd.exe".)

Note that by default ExifTool writes its output in UTF-8, so if you direct the output to a file:

exiftool -@ myargs.txt

your plugin will be able to read it and interpret all the Unicode characters correctly.

As of today, the ExifTool documentation about using it on Windows is incorrect. I've corresponded with the ExifTool author and suggested rewritten documentation that clarifies the situation: http://u88.n24.queensu.ca/exiftool/forum/index.php/topic,8382.msg43116.html#msg43116

TOPICS
SDK

Views

433

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
no replies

Have something to add?

Join the conversation