Rename using Custom Data for human being


Hi,
Because this is not implemented in DT, I’m trying to understand how to rename files using Custom MetaData.
Seems we can use something like those things :

  1. “AppleScript”. I absolutely don’t know what it is and how to record or what to do
  2. There is a *rename using RegEx" menu. Unable to use it. What is RegEx?
  3. Seems we can use Ajax ? (hu?)

I simply want to use the “identifiant” to rename my file
But I’m not a software engineer and to not have time to learn but to use my data

Any help welcome

When processing inbox items, I use an Applescript to rename the file;
see sample below for set name of theNote to theTitle
I use additional code to derive theTitle; it can reference custom metadata

tell application id "DNtp" 
		set theNote to move record theNote to theFilingGroup
		set name of theNote to theTitle
end tell
1 Like

This script renames based on Custom Meta Data.

Please try it with duplicates.

Setup

  • Open Script Editor.app
  • Paste the script
  • Replace mdextags in line set thisRecord_CustomMetaData_Value to mdextags of thisRecord_CustomMetaData with md plus your Custom Meta Data identifier
  • Save script to DEVONthink’s script menu folder
    ~/Library/Application Scripts/com.devon-technologies.think3/Menu/

Usage

  • Select some records in the item list (or one of the other views).
  • Run script via DEVONthink’s script menu.
-- Rename records based on Custom Meta Data

tell application id "DNtp"
	try
		set theRecords to selected records
		if theRecords = {} then error "Please select some records"
		
		repeat with thisRecord in theRecords
			set thisRecord_CustomMetaData to custom meta data of thisRecord
			try
				set thisRecord_CustomMetaData_Value to mdextags of thisRecord_CustomMetaData -- replace mdextags with "md" plus your identifier
				set name of thisRecord to thisRecord_CustomMetaData_Value
			end try
		end repeat
		
	on error error_message number error_number
		if the error_number is not -128 then display alert "DEVONthink" message error_message as warning
		return
	end try
end tell

1 Like

Hi,

Thank you for your answer.
I’ve put a test file in Inbox and run the script but nothing happens.
When I launch this script from AppleScript an error occurs

What is it this script supposed to do?
It opens a box or something and then I manually enter the name?

About the error : do I have something to do with “the note” variable?

Thank you to give some of your time to help me.

I’ve edited the script this way but nothing happen (I don’t know how to embed this script in this message) :

-- Rename records based on Custom Meta Data
tell application id "DNtp"
	try
		set theRecords to selected records
		if theRecords = {} then error "Please select some records"
		
		repeat with thisRecord in theRecords
			set thisRecord_CustomMetaData to custom meta data of thisRecord
			try
				set thisRecord_CustomMetaData_Value to md_company of thisRecord_CustomMetaData -- replace mdextags with "md" plus your identifier
				set name of thisRecord to thisRecord_CustomMetaData_Value
			end try
		end repeat
		
	on error error_message number error_number
		if the error_number is not -128 then display alert "DEVONthink" message error_message as warning
		return
	end try
end tell

What I want is to rename the selected file with those 3 identifier :

  • company
  • date (need to be yyyymmdd)
  • objet

As a result my files will be organized by emitter / date and objet.

(in next lige I will learn to use IA to detect date and other stuff) :slight_smile:

Yes, it can’t run. The code contains several variables which are not declared in this code.

I guess @DTLow posted it to show how a record theoretically could be renamed via AppleScript.

However, I think it’s not a good idea to post code that won’t run without modifications without making potential users aware of the fact that it won’t run. That’s especially important in case of users who have no scripting/programming background (yet).

I posted a script that does what you asked for in your first post.

Now you changed your goal. May I ask why? Did you initially forget to mention what your desired output names should look like? Please don’t take this as offensive, I’m really just curious.

It’s always a good idea to

  • post an example of the desired output (e.g. Apple - 2022-02-27 - MacBook Pro)
  • post the type of your Custom Meta Data
2 Likes

As per @pete31, this was not a complete script - just sample code to illustrate renaming a file
I did mention “additional code”; the post is edited to say “sample”

I’m sorry this wasn’t clearer
It’s not the first time that someone copies code without thought or understanding,
and reports “it doesn’t work”
There’s also the problem with clearly defined requirements

About the error : do I have something to do with “the note” variable?

As per the error message, you have to define variable theNote
There are various options using additional code; I like the *selected records" in the above script

1 Like

Hello,

In fact I did not change but was not able to explain what I want to do at first.
I thought I was far easier and while thinking about it, I discovered date format is not the same.
I thought I was simply able to catch the data and use it as a name. But it seems far far far much complex.
Just need to manage file not become a software engineer :slight_smile:

My desire output is exactly this " emitter - yyyymmdd - object"

You are right, I have exactly no background at all. For me Applescript is absolutely not understandable.
It seems it will take month to understand what to do with Applescript.

Hello

Thank for your time.
Your script does not work either. Nothing happen.
In fact, I don’t understand what do I have to adapt.

I’ve change

				set thisRecord_CustomMetaData_Value to mdextags of thisRecord_CustomMetaData -- replace mdextags with "md" plus your identifier


				set thisRecord_CustomMetaData_Value to md_company of thisRecord_CustomMetaData -- replace mdextags with "md" plus your identifier

But nothing happen.

I’me really afraid I can’t conclude this project easily,

Here are the type of data :

And the ideal output :slight_smile: (manually encoded)

Strangly, the document date is not dd/mm/yyyy but dd/mmmm./yyyy :slight_smile:

Why do you put an undescore between „md“ and your identifier?

Because if do not put the underscore, I can’t save the file and got an error message

And if I had a “+”, I can save but nothing happen either

The error is expected behavior because you didn’t change the line correctly.

Please read my instructions again. Then look at my example line. Then look at your changed line. Do you find the difference?

I can’t understand. I’ve replaced mdextags
That’s crazy, I can’t see from where comes the problem. Do I become silly?
You write “replace mdextags with “md” plus your identifier”
Do I need to write md or “md”?

So in empiric way :

if I add “plus” : error

Same here.

Really I do not see what to do??

Look at my example line.

“md plus your identifier means”

mdidentifier

not
md_identifier
nor
md identifier

Great!!
Understood. mdextags means metadata extags… really hard to reverse engineering such a thing

I’ve tried “md”+; mdplus; etc etc

Finally it works thanks.

Next step, concatenate more metadata and reverse date dd/mm/yyyy in yyyymmdd format :slight_smile:

I‘ll leave this to you.

great, thank you

seems pretty hard, but how knows

will try this : AppleScript string tip: How to concatenate strings | alvinalexander.com

I reply to myself if one day somebody wants to do the same thing without have to learn a new langage etc