ExifTool Forum

ExifTool => Newbies => Topic started by: Stephen Marsh on May 17, 2017, 04:34:59 AM

Title: Copy Photoshop Layer Text to Tag with Regular Expression
Post by: Stephen Marsh on May 17, 2017, 04:34:59 AM
I'm not having much luck copying a Photoshop layer text content to another tag.

I can see that the source tag is correct, namely:

exiftool -XMP-photoshop:TextLayerText 'FILE.psd'


or

exiftool -Photoshop:LayerUnicodeNames 'FILE.psd'


Output for example could be:

Layer 0, Layer 1, Layer 2


And I only need the bottom, first named layer content in the stack – such as: Layer 0 (removing the first comma and everything afterwards)... so a regular expression similar in part to:

,.*
or
(?!^),.*

Should be part of the answer.

However, even without tring to add the RegEx, I am having no luck:

exiftool '-title<TextLayerText' 'FILE.psd'
or
exiftool '-title<${Photoshop:LayerUnicodeNames}' 'FILE.psd'

Errors with:

Error: Bad Photoshop IRB resource "MeSa"
0 image files updated
1 files weren't updated due to errors
Title: Re: Copy Photoshop Layer Text to Tag with Regular Expression
Post by: Phil Harvey on May 17, 2017, 07:21:27 AM
Hi Stephen,

The Bad IRB resource is unrelated to what you are trying to write.  Could you send me the sample PDF so I can take a look?  My email is philharvey66 at gmail.com

- Phil
Title: Re: Copy Photoshop Layer Text to Tag with Regular Expression
Post by: Stephen Marsh on May 17, 2017, 07:29:27 AM
Thanks Phil, I have recreated the test files and yes, the command now works... So now all I need to do is to work out the regex to keep the all characters before the first comma and remove all characters after the first comma. I believe that I know the regex, however trying to work out the syntax to include this into the command is a little trickier.

Yes, I'll email the two test files to you, they were created from Photoshop CC17 using variables/data sets (data driven graphics).
Title: Re: Copy Photoshop Layer Text to Tag with Regular Expression
Post by: Phil Harvey on May 17, 2017, 07:52:56 AM
I got the files, thanks.

I've found a reference for the new MeSa IRB, and I'll add support for this in ExifTool 10.53 so you will be able to write these files with this version of ExifTool.

- Phil
Title: Re: Copy Photoshop Layer Text to Tag with Regular Expression
Post by: Phil Harvey on May 17, 2017, 08:23:16 AM
ExifTool 10.53 is now available.

- Phil
Title: Re: Copy Photoshop Layer Text to Tag with Regular Expression
Post by: Stephen Marsh on May 17, 2017, 05:20:10 PM
Thank you Phil.

I have searched the forums and although I can find references to achieving specific tasks using regular expressions, I can't seem to achieve the following:

Layer Zero, Layer 1, Next Layer, And another one

Simply removing everything including the first comma and all remaining characters.

I know my regex works, however I am getting caught up in the ExifTool syntax.

,.*
or
(?!^),.*

Can somebody please point me to posts explaining the syntax or show me where I am going wrong?
Title: Re: Copy Photoshop Layer Text to Tag with Regular Expression
Post by: StarGeek on May 17, 2017, 06:36:52 PM
There are a variety of ways to do that.  You could try something like
exiftool '-title<${TextLayerText;s/(^[^,]*).*/$1/}' 'FILE.psd'
Here's how it works (https://regex101.com/r/eWBRj3/1) on Regex101.  You can see the step by step break down in the upper right corner.

Another way is
exiftool '-title<${TextLayerText;s/(^.*?),.*/$1/}' 'FILE.psd'
Regex101 again (https://regex101.com/r/eWBRj3/2)

Edit: Fixing your expression would be this
exiftool '-title<${TextLayerText;s/,.*//}' 'FILE.psd'
Regex101 (https://regex101.com/r/eWBRj3/3)
Title: Re: Copy Photoshop Layer Text to Tag with Regular Expression
Post by: Stephen Marsh on May 17, 2017, 07:34:46 PM
Thank you StarGeek!

Your last example is pretty much what I was expecting:

exiftool '-title<${TextLayerText;s/,.*//}' 'FILE.psd'

At least for the pure RegEx part, however I am just trying to work out the ExifTool/Perl syntax around it...

So, we need to add:

${

Then at the end of the source tag we add:

;s

Then an opening:

/

Now we plug in our regex:

,.*

Followed by two closing (escaped?):

//

Finally a closing brace/curly bracket:

}

Although it would be helpful to understand why, I don't really need to know if all I have to do is plug-in my regex into such a structure. Not understanding the required syntax, I just need to work out the "scaffolding" around the regex that I know works.

I'll need to study your other examples a little deeper, this is the great thing about regular expressions, so many ways to the same end...
Title: Re: Copy Photoshop Layer Text to Tag with Regular Expression
Post by: StarGeek on May 17, 2017, 07:58:08 PM
Quote from: Stephen Marsh on May 17, 2017, 07:34:46 PM
Then at the end of the source tag we add:

;s

Then an opening:

/

Followed by two closing (escaped?):

//

Not quite.  The semicolon is there to mark the end of the tag name and start of the advanced formatting.  Everything following that should be perl statements, which have a semicolon as a statement delimiter.

The actual perl statement is regex substitution, which is s/Search/Replace/options;.   The slashes are standard, but Perl doesn't require you to use slashes.  You can use other characters.  For example, you'll often Phil use parenthesis () (example (https://exiftool.org/forum/index.php/topic,5812.msg28448.html#msg28448)) instead of slashes.  So your command could just as easily be exiftool '-title<${TextLayerText;s(,.*)()}' 'FILE.psd'.  The reason you might use something else is because if you have too many slashes you have to escape in your regex, it becomes hard to read (see Leaning toothpick syndrome (https://en.wikipedia.org/wiki/Leaning_toothpick_syndrome)).

Ah, here's a good post (https://exiftool.org/forum/index.php/topic,4827.msg23110.html#msg23110) from Phil. 

QuoteI'll need to study your other examples a little deeper, this is the great thing about regular expressions, so many ways to the same end...

I often recommend Regular-Expressions.info (http://www.regular-expressions.info/) as a site to learn about regular expressions.  And Regex101.com (https://regex101.com/) is a great site where you can test out your regex. 
Title: Re: Copy Photoshop Layer Text to Tag with Regular Expression
Post by: Stephen Marsh on May 19, 2017, 02:35:06 AM
Thank you StarGeek, that is really helpful and a great place to start in working this all out, cheers!