How do I copy tags from file to another file? [solved]

I’m collecting on movies and type many tags for each movie. I use the application Skreenics to create screen caps from movie files and my goal is to copy all tags from file1.mp4 to file1_screencaps.jpg. So is it possible to create a script that you copy only the tags from the movie files with the same name to the screencaps.jpg files. For example:

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

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

This script convert keywords to tags and maybe can be a great start for make changes to the script:

tell application id "com.devon-technologies.thinkpro2"
		set these_items to the selection
		if these_items is {} then error "Please select some contents."
		repeat with this_item in these_items
			set this_comment to the comment of this_item
			if this_comment is not "" then
				set {od, AppleScript's text item delimiters} to {AppleScript's text item delimiters, ","}
				set theTags to text items of this_comment
				set AppleScript's text item delimiters to od
				set theTags to (parents of this_item) & theTags
				set the tags of this_item to theTags
				set the comment of this_item to ""
			end if
		end repeat
	on error error_message number error_number
		if the error_number is not -128 then display alert "DEVONthink Pro" message error_message as warning
	end try
end tell

I also get help from Christian before when I need help to copy the thumbnail image to the movie file

tell application id "com.devon-technologies.thinkpro2"
   set theSelection to the selection
   repeat with theRecord in theSelection
      set thePath to path of theRecord
      set thePath to ((characters 1 thru -4 of thePath) as string) & "jpg"
      set thumbnail of theRecord to thePath
   end repeat
end tell

I think a mix of this codes will be the solution for the thing I request for, but I don’t know how to fix this myself. So please help me…

Here’s a simple example:

-- Copy tags from movies to screen captures

property pExtensions : {".avi", ".mp4"}
property pSuffix : "_screencaps.jpg"

tell application "DEVONthink Pro"
	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

1 Like

Thousand thanks for this script Christian!
It works perfectly and was exactly what I was looking for :smiley: