Update custom metadata fields from filename

Since version 3 I am bringing my receipts into a Database.

A Receipt is scanned from my phone with a file name ( ITEM_AMOUNT ) this is passed to a folder in iCloud Drive that Hazel watches and then Hazel adds a creation date so the final filename is ( DATE_ITEM_AMOUNT / 06-12-2019_TRAVEL_20.00 )

Previously this file would be filed in a finder folder, but now with version 3 I am interested in importing into Devonthink.

So I have an additional hazel rule that now moves the file to the Devonthink Inbox folder.
Devonthink then takes over with a Smart Rule that files the item into a group which is created every calendar month, by the smart rule.

At the end of the month I would then work in Apple Numbers on these expenses. I do this for both personal and work expenses.

I was then looking at “create metadata overview” over the last few days and I saw a post regarding the new script for creating expense reports, with the new update.

So I have now created custom metadata fields, see screenshot. ( I might remove the Date from this, as the file created date makes this field not required )

Create Metadata overview seams great as it also creates a column for the links to the original file. Especially as then I have link backs to original receipts from an Apple Numbers sheet.

This would considerably improve my workflow.

So to my Question/Hope

Is there a way to create a rule and I think would need a script, that could parse, the filename and add the info to the separate metadata fields. I hope this could be done with out a script but doubt this. So as the Receipt is passed to the correct group the Metadata could be updated automatically via the rule. this would mean I would then only have to create this metadata overview / expense sheet that I could then import into Apple Numbers monthly.

I hope all is clear and thank you for any help with this.

I was not sure if I should add to the post about create expense report but decided to create a new post as question is more related to metadata generally. Please move if you wish.

Thanks again for any info.

This will probably require a script. How do the filenames actually look?

thanks for quick reply, please see attachment to show how the file names actually look in Deventhink.
I have a running list of over 60 Item names that change depending on the actual item of the receipt.

Thanks for the screenshot. Smart rules can’t handle this by default, a script would be definitely necessary.

Thanks for info

I managed to take a step further,

In a smart rule the metadata fields are available as an option, I can then insert a placeholder option.
I used the Proposed name - which is taking from the OCR - for the ITEM field.
I used Amount - but I had to put that in NOTE field as is it seams I am unable to add a placeholder in either of the amount or price metadata feilds. I assume due to the number formatting?

It has given me about a 50% success rate on reading the OCR for name and amount,
Would it be possible, in the future, to add a placeholder to amount or price data fields ?

I could even just add name instead of proposed and then delete what’s not needed as all is in name, depends how accurate OCR is.

I haven’t learnt the art of writing scripts but its fun finding these options
Thanks for a great update. !!!

OK I am still trying this.
I created a drop down list of all the Items in the custom metadata field, this is cool, as I do not have to type again and is quicker than copy and paste.

The next part is the part I still sort of can not get to work …
In hazel, using custom attributes, I managed to copy the amount from the filename and add to file comments ( what I think is finder comment ) before the file is imported into Dt

In Dt
I then changed the rule and created a new metadata field which I thought would look at the comments field - I have tried both finder comment and comment, I left as Single line text and Multi Line text so I can insert the placeholder

Please see screen shots
Any ideas why the comment does not appear in the metadata after the rule runs,
BUT have just checked … it does appear in the finder comment column view

Thanks again

What’s the purpose of this new custom metadata? Unfortunately it’s unclear on your screenshot how the final rule actually looked.

apologies I thought was clear
What I was still trying to do was get the amount into a custom meta data field with out retyping - so as to avoid any mistype.

I needed two metadata feilds. I was trying to avoid OCR.

1 the ITEM this is now handled by drop down box in metadata field itself, so thats all good so not needed in rule.

2 The Amount. I can not seam to get this bit to work

I can now get the amount separated from the file name ( in hazel ) and added to finder comment

What I wanted here is to then get a metadata field to pull from this finder comment.

It seems you can create a custom field into metadata from the Finder comment but from my rule it does not populate

Even though I have now created a column ( finder comment with amount ) in the sheet automatically which originally was the end goal
I am just now trying to get in the custom metadata area as is easier to read when going through the files in Devonthink

Its the last part of the rule that does not seam to work ( move and file into work ) change comment to finder comment is what I’m having trouble with

Please see screenshot

Thanks again for any help

The Change Comment action actually changes the Finder comment, therefore the last action doesn’t do anything.

Ahhh yes. my mistake

I have now got it to work, brilliant thanks for help with this

Quick Question about rule backup.

Are Rules saved into the DT database files? I back these up.
or is there anything else I need to do to have a backup of the rules. do I need to hunt a Plist file and back that up ?

The rules are stored in ~/Library/Application Support/DEVONthink 3/SmartRules.plist.

:sunglasses: Thankyou

It seems to me the best way to do this is to have Hazel extract the metadata from the file name as custom attributes and then run a script adding the file to DT with those custom attributes inserted as metadata (haven’t tried this but assume it is doable).

Another way would be to use a shortcut in iOS (assuming you have DTTG) and add the entry using an x-url (again, I’m assuming custom metadata can be added that way- somebody correct me if I’m wrong).

In the end, I did use Hazels custom Attributes to extract the amount from the file name, which then was added to finder comment, this could then be used by Dt rules.

( I added to Finder comment as did not see where else would be best to create the info )

For the iOS part my workflow at the moment is a quick scan with ScanBot app which has tags I can quickly use, so I only have to type amount and is then automatically uploaded to Dropbox where Hazel moves on import to DevonThink Inbox Where the rules move to correct group and create the Metadata needed.

I look forward to when, hopefully something like custom attributes arrives in DevonThink

What would be the difference to custom metadata (see Preferences > Data)?

I am still working though my understanding of the possibilities of using the new rules and custom metadata, so apologies if I have missed something.

I see something like Hazel custom attributes and match patterns as being able to create data that Devonthink’s custom metadata would then be able to act on. A way of bringing in actionable data. My recent example of trying to extract the amount from the end of the filename as one example.

It might be they are already there in the form of operators and wildcards in Devonthink but being able to drag ‘tokens’ around was certainly simpler.

‘If all / any of the following are true’ … condition was able to handle placeholders, this would maybe answer this need ? Please see screenshot from the Hazel Rule I used.

I think there is value in further building out Deventhink rules. It is not trying to replace hazel within Devonthink obviously.
The addition of Smart Rules to V3, I Think has opened up so much utility. I realise that you guys have gone through a large release and most probably need a rest but for when the time comes if you can consider building out the rule options a much as possible. Would be great.