How specifically do we use regular expressions? I am trying to see if I can have DT do what Hazel does:
- Match PDF file for content
- Rename based on data from the PDF. (iCloud Subscription - May 15, 2020)
How specifically do we use regular expressions? I am trying to see if I can have DT do what Hazel does:
What are you expecting to find?
As noted in the Help > Documentation > Appendix > Smart Rule Events and ActionsâŚ
It is best to start off simply with an action that can be used for debugging, like Display Alert. That was you can more easily test if youâre getting the expected results or not. Then add subsequent actions as needed.
Thank you. It would help if a screenshot that you posted was included in the manual as it makes a lot more sense.
I got excited for a moment thinking that I can have DT scan for total $ value in a receipt and then change the custom metadata âtotalâ to the $ found inside text. However, I see that I cannot set custom metadata to the RegEx result.
I assume that this can be done with an Apple Script?
Workflow example:
For each document do:
Problem is I donât know how to write an Apple Script.
Please advise.
Figured it out. DT Already includes an Apple Script inside Smart Rules folder. The script is called âAssign Document Date & Amount.â
I made a copy and named it Assign Document Total. Total includes the price with tax.
Script Content:
-- Assign Amount
on performSmartRule(theRecords)
tell application id "DNtp"
repeat with theRecord in theRecords
try
set theAmount to document amount of theRecord
add custom meta data theAmount for "Total" to theRecord
end try
end repeat
end tell
end performSmartRule
Result:
Because the Amount parameter doesnât accept regular expressions. Itâs returning nothing and the Document Total is only getting added by the Execute Script action.
Doh! What would be a proper Apple Script to include Scan Text for Amount inside of the script?
I would like to select several PDF files and have DT Apple Script Find and Set the Total to each one.
-- Assign Amount
try
tell application id "DNtp"
set this_selection to the selection
if this_selection is {} then error "this_selection select some contents."
repeat with this_selection in theRecords
try
set theAmount to document amount of this_selection
add custom meta data theAmount for "Total" to this_selection
end try
end repeat
end tell
end try
What was the result of the script you just posted?
Nothing
Does this include scanning the document for the amount?
set theAmount to document amount of this_selection
Yes, this property (and the same placeholder in smart rules) scan the text of the document. Could you send a copy to cgrunenberg - at - devon-technologies.com? Thanks!
@cgrunenberg, is it possible to use the regex capture group (from the smart-rule) in an applescript (in the same smart-rule)?
No, since there are no variables and data isnât passed between actions in a smart rule.
Great, nice work @cgrunenberg and the crew! This eases my script workaround.
Any details about the regular expression âdialectâ that is used? Is it ICU?
Any more thoughts on the script to make it work? Does it work on your end?
In this state it returned a value, though it was actually not the correct amount.
tell application id "DNtp"
repeat with this_selection in (selection as list)
set theAmount to document amount of this_selection
add custom meta data theAmount for "Total" to this_selection
end repeat
end tell
Donât use try⌠end try
blocks while youâre debugging. It masks errors in the code.
Thank you. It works now. Although a hit and miss for proper number.
No problem and remember, itâs only a computer