The copy tags from file to another file doesn't work anymore for me in DT 3.8.6

Hi!
I have get a working script before to copy tags from a movie file to a screenthumb file.
For example:

file1.mp4 → file1_screencaps.jpg
file2.avi → file2_screencaps.jpg and so on…

Today I use more file1.mp4 → file1.jpg
file2.wmv → file2.jpg and so on.

This script doesn’t work anymore for me or need to be adjusted I think:

-- Copy tags from movies to screen captures

property pExtensions : {".avi", ".mp4", ".mov", ".mpg", ".mpeg", ".wmv", ".rm"}
property pSuffix : ".jpg"

tell application "DEVONthink 3"
	set theSelection to the selection
	repeat with theRecord in theSelection
		set theName to name of theRecord
		repeat with theExtension in pExtensions
			if theName ends with theExtension then
				set extensionLen to length of theExtension
				-- Works only as long as the name doesn't contain / which should be replaced with \/ in locations
				set theLocation to location of theRecord & (characters 1 thru -(extensionLen + 1)) of theName & pSuffix
				set theDatabase to database of theRecord
				set theOtherRecord to get record at theLocation in theDatabase
				if exists theOtherRecord then set tags of theOtherRecord to tags of theRecord
			end if
		end repeat
	end repeat
end tell

Many thanks in advanced for helping me with this :smiley:

1 Like

Did you run the script in script editor? If so, what are the messages in the debug pane telling you?

I have these test tags in a movie clip:

movie
tag1
tag2
test

I get the following result from movie.wmv with the thumbnail file movie.jpg:

tell application "DEVONthink 3"
	get selection
		--> {content id 33431 of database id 1, content id 33443 of database id 1}
	get name of content id 33431 of database id 1
		--> "Movie"
	get name of content id 33443 of database id 1
		--> "Movie"
end tell

It seems like the tags section doesn’t do anything in the script?

1 Like

I forgot to say I running Monterey 12.5.1 for now if it has something to do with my Mac OS version?

that returns the name of the record without its extension (in my experimenting even if Show filename extensions is set in the preferences); I suspect that may once have been otherwise, as the dictionary contains a name without extension variable.

If you use path of theRecord the extension will be at the end of the variable as expected, so try this:

-- Copy tags from movies to screen captures

property pExtensions : {".avi", ".mp4", ".mov", ".mpg", ".mpeg", ".wmv", ".rm"}
property pSuffix : ".jpg"

tell application "DEVONthink 3"
	set theSelection to the selection
	repeat with theRecord in theSelection
		set theName to name of theRecord
		set thePath to path of theRecord
		repeat with theExtension in pExtensions
			if thePath ends with theExtension then
				set extensionLen to length of theExtension
				-- Works only as long as the name doesn't contain / which should be replaced with \/ in locations
				set theLocation to location of theRecord & name of theRecord & pSuffix
				set theDatabase to database of theRecord
				set theOtherRecord to get record at theLocation in theDatabase
				if exists theOtherRecord then set tags of theOtherRecord to tags of theRecord
			end if
		end repeat
	end repeat
end tell

If in doubt, use name without extension where I have used name just in case things change in the future.

2 Likes

Thanks for the script!

I get more debug information now but it doesn’t work yet:

check that the extension of your jpegs really is .jpg and not .jpeg

Edit: ah, stop: I changed the script moments after posting it and after having tested it; pls use the current version posted above; you copied it before I had made the change (sorry about that!)

Yay! Now it works, what was the difference here from the older script?
Thank you so much for this :smiley:

1 Like

I had omitted to change the line which removed the extension from the name (that removal, of course, isn’t necessary because the name doesn’t contain the extension).

So this

set theLocation to location of theRecord & (characters 1 thru -(extensionLen + 1)) of theName & pSuffix

became this:

set theLocation to location of theRecord & name of theRecord & pSuffix

@cgrunenberg: with regards record, both name and name without extension return the same value; is that intentional? (I see you wrote the original script approx. 2012, so for DT2 - I guess the behaviour changed with DT3)

Please do not post screenshots if you want to show code. I for one can’t read this stuff, it’s so small. And much less can anyone try it out.

Code is meant to be run, not typed in from a screenshot.

Sorry, it was only to show the debug process information how the script was running…

Which is not helpful either if one can’t properly read the script code because it’s too small.
The messages can be copy/pasted, too.

I understand, it will not happen again…

1 Like