[I’m posting here to don’t mix up the threads]
Over here this query
mdbookends!=
results in all records whose meta data “Bookends” is not empty.
[I’m posting here to don’t mix up the threads]
Over here this query
mdbookends!=
results in all records whose meta data “Bookends” is not empty.
Pete, if you’re swamped, we can kick the can on this. It’s low priority—just an annoyance. I don’t understand what I’m supposed to do with the mdbookends!=
operator. I know I’m to swap “bookends” with the actual metadata identifier (from my own metadata). All I need to know, is where that goes. Does this go in one of the scripts you authored and provided in the other thread?
Perhaps a digression, I clicked just now on List & Record Tools.osax
in my ScriptingAdditions folder. It launches this, in ScriptEditor:
I’m relieved to understand (through your last comment) that info I wished to acquired, through a query of some sort, can at least be achieved somehow!
Sorry @Ryan_N I shouldn’t assume that every user knows DEVONthink’s search syntax.
mdbookends!=
is what DEVONthink shows in its search field when you select custom meta data “Bookends” with is not
and leave the text field blank.
This results in all records where “Bookends” is not empty
It has nothing to do with the scripts.
Das ist voll fett! @pete31 I’ll come back and edit this after I figure out–with your help hopefully–how to run the “Main” script. (I really do need to learn code!)
I thought that all I had to do, was enter the metadata IDs I wish to permanently delete, but I get an error on the word “permanent.” If you’re willing to edit your script with my IDs, I can simplify the instructions (and this comment) for anyone searching this in the future. In your main script (“Script 2”), my IDs would be: “mdcatalogtitle”, “mdcorr.ocr”, “mddiscoverycredit”, “mdhighinterest?” (In other words, I don’t know how to modify your second (“main”) script to work for me.)
The solution to my OP however, was in your comment just above!
md[custom metadata ID]!=
(excluding brackets, including “!” and “=”) whereas “custom metadata ID” is actually just that, but note: your custom metadata ID might be different than it’s label!Pete; a generic question/digression: is there a reason you used the “IS NOT” operator in your query?
For instance, would I get different results using “IS” or “Contains” instead?
So to bring this full circle now, each item on that list should then be queried from within DT3 using the method described in #1 above.
The next step is to run Script 2, the “main” script, to permanently inoculate the unwanted metadata field (but Pete, I’ll need your help first—then will come back here and edit/update this).
Do you mean you ran it but it didn’t remove meta data?
Correct.
Do you mean meta data is “coming back”? If so: where do you see it coming back? More general: What do you expect as result of running the main script? Did you verify the result with script 3?
Sure, it’s a very nice idea to write proper instructions. That’s often the hardest part when writing and posting scripts, especially as I’m no native speaker (“Das ist voll fett!” ) and it’s often quite hard to anticipate what users need to know.
-- Delete Custom Meta Data
use scripting additions
property deleteMetadataNames : {"mdcatalogtitle", "mdcorr.ocr", "mddiscoverycredit", "mdhighinterest?"} -- set your Meta Data Identifiers here
tell application id "DNtp"
try
set theRecords to selection of viewer window 1 as list
if theRecords = {} then error "Select some records"
set theButtons to {"Cancel", "Delete"}
set theButton to button returned of (display alert "Delete this Metadata from selected records?" buttons {item 1, item 2} of theButtons default button 1 message my tid(deleteMetadataNames, linefeed) as critical)
if theButton = item 1 of theButtons then return
show progress indicator "Deleting given Metadata... " steps (count theRecords) as string with cancel button
repeat with thisRecord in theRecords
step progress indicator (name of thisRecord) as string
set thisMetadata to custom meta data of thisRecord
try
set newMetadata to thisMetadata
set thePropertyNames to my getPropertyNames(thisMetadata)
repeat with thisPropertyName in thePropertyNames
if (thisPropertyName as string) is in deleteMetadataNames then set newMetadata to my deleteUserProperty(thisPropertyName as string, newMetadata)
end repeat
if newMetadata ≠ thisMetadata then set custom meta data of thisRecord to newMetadata
end try
end repeat
hide progress indicator
on error error_message number error_number
hide progress indicator
if the error_number is not -128 then display alert "DEVONthink" message error_message as warning
end try
end tell
on tid(theList, theDelimiter)
set d to AppleScript's text item delimiters
set AppleScript's text item delimiters to theDelimiter
set theList to theList as text
set AppleScript's text item delimiters to d
return theList
end tid
on getPropertyNames(theMetadata)
set thePropertyNames to get user property names theMetadata
end getPropertyNames
on deleteUserProperty(thePropertyName, theMetadata)
set theMetadata_new to delete user property thePropertyName in theMetadata
end deleteUserProperty
If this shouldn’t work as expected please remove identifier mdhighinterest?
and try again. Not sure whether the question mark could screw up things.
“Is not” with an empty search term gives you all records whose meta data “Bookends” is not empty. That was what you wanted, I think.
“Contains” with search term bookends://
would yield the same over here as this meta data holds links, e.g. bookends://sonnysoftware.com/57308
“Is” yields in records whose meta data is exactly the search term, e.g. bookends://sonnysoftware.com/57308
finds the record, but if you added a space to the search term you wouldn’t find the record.
That’s all covered in Help > Documentation > Appendix > Search Prefixes
.
Curious if it’s working now
Okay, so I actually entered the syntax properly when I tried this last night. To cover the bases however, I re-ran the script you kindly modified just above (per my request… so huge TY again). I copy all that text, paste it into ScriptEditor (text is purple), then hit the hammer icon. What should happen, is the script converts into lots of black, red and blue, i.e. like above. But what I get instead is "Syntax Error, Expected end of line but found “property.” When it does that, it highlights that literal word, 5th from bottom line of the script. Here are some screenshots–including what I see if I click on the right of the two drop-down menus in ScriptEditor. Note: I’m running DT3.6.1 and Big Sur:
Thank you very much for this explanation. And sorry, I completely forgot to look into what you already mentioned in the other thread
No idea why I didn’t check this, would probably have saved some headache on your side. Sorry!
I just moved List & Record Tools.osax
out of /Library/ScriptingAdditions/
, and tried to compile again. Same error as yours.
That means List & Record Tools.osax
is not installed on your mac.
Please move it to /Library/ScriptingAdditions/
, then try to compile again.
Please move it to /Library/ScriptingAdditions/, then try to compile again.
Unfortunately, that’s where I had it. I did a full restart earlier today when I was troubleshooting this. Must be OSX related, but strangely I can double-click the .osax file and see his directory in an AppleScript window. I installed that file per the developer’s instructions by placing it in my user-account ScriptingAdditions folder. But just for kicks, I copied the file and put it in the ScriptingAdditions folder that also exists in the hard drive’s parent “Library” ("Mackintosh HD > “Library” --or in other words; the Library folder that isn’t within my computer’s “user” account–the thing I log-in to when I boot my computer up from a cold start. I initially placed the file under (my username) > Library—i.e. by way of opening the Finder, holding Option and clicking “Go” to access the Library. The file remains there as well.
In my case, it was really only that query you shared that I needed. If the metadata stays, I really don’t care; it won’t be a problem. The only thing that truly suffers is my own mental glory in completing this little task all the way though . My suspicion is that we’re dealing with an unsolvable conflict with the OS in this case.
Welcome to the troubles of dependencies.
There’s no other way to do it. As far as I know is what “List & Record Tools.osax” does not possible with vanilla AppleScript. Seems its functions could be replicated in AppleScriptObjC, however as long as it works for me I won’t try that.
Umm… from the download page of that osaxen:
LIST & RECORD TOOLS
NO LONGER MAINTAINED
Change History/Release Notes
1.0.6 June 28, 2010
Support 64-Bit Intel systems.
Yes, I know, however it works fine over here (on Mojave).
The best way would of course be adding an AppleScript command to DEVONthink that really deletes meta data.
Then users could get rid of it if it’s no longer needed. That may be not an important issue now, however in some years users might have collected a lot of meta data that they no longer need. Adding a command in the near future would serve users who already are facing unwanted meta data.
Feature request: Please add a way to completely delete meta data from a record.
Thanks!
The next release will simply support this by also accepting empty arrays (as it’s unbelievably complicated in AppleScript to define empty records/dictionaries):
set the custom meta data of item 1 of selected records to {}
So this means we can
right?
This should all be possible, actually only the second step isn’t possible right now.
Awesome Thanks a lot Criss
The next release will simply support
@cgrunenberg may I suggest, also, some sort of “are you sure” warning to present before metadata fields in Preferences > Data are actually deleted? Right now, pressing the little minus icon instantly deletes the currently-selected metadata field. Some sort of warning seems appropriate so as to rescue some idiot like me who might have the WRONG field selected and/or not intend to depress that minus button in the first place.
Many thanks for incorporating an actual script for true deletion of metadata in a future edition. I agree with Pete that this could really come in handy for many users. Cheers!
Actually only the definition/preference is deleted, not the actual metadata of the files. But we’ll add an alert.