How to fill user defined information from tags?

Dear,

in the past I used another DMS to manage my documents and have now (for several reasons) switched to DT3.
To get my documents over quite smoothly, I used Hazel to tag some information that I did not want to take into the filename (e.g. account number).
After having my documents gone to DT3, how can I get the tagged content to be filled into some user defined fields in the information pane?

As I know that I need to identify the tags, I have named them properly (from my perspective).

As an example:

I have a PDF-File which is tagged with “bel:12345678” and I have a user defined field called “Belegnummer”. How do I get the 12345678 into that field?

Thank you for pointing me into the right direction.

Best regards,

Philip

You can’t do this without scripting.
Here is a simple bit of code - written very simply - that would accomplish the task…

tell application id "DNtp"
	repeat with thisRecord in (selection as list)
		set docTags to tags of thisRecord
		repeat with thisTag in docTags
			if thisTag begins with "bel:" then
				set belValue to (characters 5 thru -1 of thisTag)
				set belValue to (belValue as string)
				add custom meta data belValue for "belegnummer" to thisRecord
				exit repeat
			end if
		end repeat
	end repeat
end tell

This could be saved and run as a script or even used as an embedded or external script in a smart rule.

Thank you for your swift feedback.
Do I judge this right, that adding a remove statement will also remove the original tag like this:

tell application id "DNtp"
repeat with thisRecord in (selection as list)
	set docTags to tags of thisRecord
	repeat with thisTag in docTags
		if thisTag begins with "bel:" then
			set belValue to (characters 5 thru -1 of thisTag)
			set belValue to (belValue as string)
			add custom meta data belValue for "belegnummer" to thisRecord
                            remove thisTag
			exit repeat
		end if
	end repeat
end repeat

end tell

adding a remove statement

No, that would not work.
Is this a separate inquiry from your initial one, i.e., how to remove tags?

Is this a separate inquiry from your initial one, i.e., how to remove tags?

Not from my perspective. The idea was to simply enhance the process by deleting the tag that was just processed. But if it does not work that simple, I will try to remove all tags afterwards, as for general removing tags there are quite a few ideas around in the forum.

Best regards,

Connor

The idea was to simply enhance the process by deleting the tag that was just processed.

I am a little confused.
Are you saying you’d like to remove the tag that generated the custom metadata?

Are you saying you’d like to remove the tag that generated the custom metadata?

Long story short: yes.
Long story long:

When preparing the data via Hazel, I have tagged different information that will be added to the custom metadata. To separate these different information, I used different “keys” like “bel:” for “Belegnummer”.
The idea is

  • to use the script you provided (once again thank you) to fill the metadata (which is the part behind “bel:”),
  • delete the tags that include the “key” and
  • finally add the “pure” metadata as a new tag to the files

Giving an example, a tag would look like this: “bel:bjdio536942394”. The script would fill “bjdio536942394” into the field “Belegnummer”.
After this, the tag “bel:bjdio536942394” would be deleted, as it is useless like this and finally, the document would be tagged with “bjdio536942394”.
Of course it would also be possible to amend the tag by shortening the “bel:” part.

I hope to have explained the idea in a proper way…

Like so:


to…

:thinking: :slight_smile:

Yes, thank you for understanding! :rofl:

Here’s an adjusted bit of code…

tell application id "DNtp"
	repeat with thisRecord in (selection as list)
		set culledTags to {}
		set docTags to tags of thisRecord
		repeat with thisTag in docTags
			if thisTag begins with "bel:" then
				set belValue to (characters 5 thru -1 of thisTag)
				set belValue to (belValue as string)
				add custom meta data belValue for "belegnummer" to thisRecord
				copy belValue to end of culledTags
			else
				copy thisTag to end of culledTags
			end if
			set tags of thisRecord to culledTags
		end repeat
	end repeat
end tell

PS: I hope you’re learning something from it :slight_smile:

1 Like

Thank you - I will try and if not have a good starting point :wink:

You can be sure. And simply because I do not want to be ending having a system running that I cannot use without external help. :grinning:

Regards,

Connor

You’re welcome! :slight_smile: