When editing custom metadata (md for short henceforth) I noticed that you can do it with multiple files as long as they have exactly the same values. For exemple, if I select files 1, 2 and 3 I can edit their md fields (a, b and c) all at once. BUT if I add file 4 (thus, having selected files 1, 2, 3 and 4) and edit a single md field (let us say field d or any other), then I files 1, 2 and 3 will loose all their remaining md values. Can this be corrected so that 1, 2 and 3 will preserve the values that weren’t altered?
2.
I have a question about adding md when creating new files. Let us say I have the following command in my script, for creating a new file:
set theAnnotationDocument to create record with {URL:sourceURL, name:annotationName, source:o_theAnnotation, type:markdown} in current group
Where exactly do I add md with the command below?
add custom meta data the_authors for "authors" to theAnnotationDocument
(Also how do I get as code highlight here on the forum?)
I have confirmed this issue and it definitely appears to be a bug. Note the Date is 2002 for all selected files, but only the first two have the Company in common. The third does does not. Selecting the first two files, the Date shows as 2002, but selecting the third file - the one without the common Company attribute - the Date is shown as 2000. Upon adding the common Company, the Date has changed.
You would add the second line after the first or you’d be referring to a variable - theAnnotationDocument that doesn’t yet exist.
Code is created by using single back-ticks - `echo testing` = echo testing
Code blocks start and end with three back-ticks.
```
tell application id “DNtp”
beep
end tell
```
resolves to…
tell application id "DNtp"
beep
end tell
And here’s an example pertaining to your code…
tell application id "DNtp"
set newRecord to create record with {name:"New Markdown", content:"## New H2", type:markdown} in current group
add custom meta data true for "Done" to newRecord
end tell
Is there a way to tell the script to, on error, set any variables not found to “” or do I have to do it individually for each variable?
There are many…
set customMD to custom meta data of sourceDocument
set the_authors to mdauthors of customMD
set the_editor to mdeditor of customMD
set the_translator to mdtranslator of customMD
set the_title to mdtitle of customMD
set the_publisher to mdpublisher of customMD
set the_date to mddate of customMD
set the_link2 to mdlink2 of customMD
set the_page to mdpage of customMD
set the_abstract to mdabstract of customMD
set the_bibkey to mdbibkey of customMD
set the_doi to mddoi of customMD
set the_sertitle to mdsertitle of customMD
set the_journal to mdjournal of customMD
set the_issue to mdissue of customMD
set the_reference to mdreference of customMD
Meanwhile, I’ll be going down the long and windy road
try
set the_authors to mdauthors of customMD
on error
set the_author to ""
end try
try
set the_editor to mdeditor of customMD
on error
set the_editor to ""
end try
try
set the_translator to mdtranslator of customMD
on error
set the_translator to ""
end try
try
set the_title to mdtitle of customMD
on error
set the_title to ""
end try
try
set the_publisher to mdpublisher of customMD
on error
set the_publisher to ""
end try
try
set the_date to mddate of customMD
on error
set the_date to ""
end try
try
set the_link2 to mdlink2 of customMD
on error
set the_link2 to ""
end try
try
set the_page to mdpage of customMD
on error
set the_page to ""
end try
try
set the_abstract to mdabstract of customMD
on error
set the_abstract to ""
end try
try
set the_bibkey to mdbibkey of customMD
on error
set the_bibkey to ""
end try
try
set the_doi to mddoi of customMD
on error
set the_doi to ""
end try
try
set the_sertitle to mdsertitle of customMD
on error
set the_sertitle to ""
end try
try
set the_journal to mdjournal of customMD
on error
set the_journal to ""
end try
try
set the_issue to mdissue of customMD
on error
set the_issue to ""
end try
try
set the_reference to mdreference of customMD
on error
set the_reference to ""
end try
try
set the_keywords to mdkeywords of customMD
on error
set the_author to ""
end try
This is just AppleScript’s handling of records which is unfortunately a little bit cumbersome. Here’s the shortest version I can currently think of:
set {the_author, the_editor, the_translator, the_title, the_publisher, the_date, the_link2, the_page, the_abstract, the_bibkey, the_doi, the_sertitle, the_journal, the_issue, the_keywords} to {"", "", "", "", "", "", "", "", "", "", "", "", "", "", ""}
try
set the_authors to mdauthors of customMD
end try
try
set the_editor to mdeditor of customMD
end try
try
set the_translator to mdtranslator of customMD
end try
try
set the_title to mdtitle of customMD
end try
try
set the_publisher to mdpublisher of customMD
end try
try
set the_date to mddate of customMD
end try
try
set the_link2 to mdlink2 of customMD
end try
try
set the_page to mdpage of customMD
end try
try
set the_abstract to mdabstract of customMD
end try
try
set the_bibkey to mdbibkey of customMD
end try
try
set the_doi to mddoi of customMD
end try
try
set the_sertitle to mdsertitle of customMD
end try
try
set the_journal to mdjournal of customMD
end try
try
set the_issue to mdissue of customMD
end try
try
set the_reference to mdreference of customMD
end try
try
set the_keywords to mdkeywords of customMD
end try
try
set the_editor to mdeditor of customMD
on error
set the_editor to ""
end try
Hi
Just wanting to understand custom meta data better by using your code as example:
If I understand correctly: the code is to retrieve data in mdeditor if it is not empty and assign the data to variable the_editor. And “” is assigned to the_editor if not.
Now, if I want to put something into mdeditor if it is not empty, should the code be something like this?
try
set the_editor to mdeditor of customMD
on error
Set pluginData to "whatever name"
add custom meta data pluginData for mdeditor
end try
Now, if I want to put something into mdeditor if it is not empty, should the code be something like this?
If the mdeditor was not empty it wouldn’t error, so the pluginData value would not get written. It would only set the_editor to the current value of mdeditor.
If you merely want to write a value to mdeditor, just use the add custom meta data command. The attribute will be created if it doesn’t exist.
Hi @ngan,
I am not entirely sure I understand where you are tying to get, but yes, if you want any value written in case the variable is empty the place it after on error.
try
set the_editor to mdeditor of customMD
on error
Set the_editor to "value"
end try
Yes, that answers my question.
I’m just experimenting to get a value from a custom md field (if not empty) or writing some value to it (if empty) for one of my pet script.
Hi, I have a related task:
I want to take a spreadsheet of metadata - for example, Author, Subject, CC for records and I want to run a script that will take the data from this sheet and sub it into the custom metadata fields “Author” “Subject” and “CC” from columns in the sheet. I have tried various language from the above, but I am struggling. I think I am missing some simple syntax. Ideally, I could take a sheet that is arranged as for example, Column 1 is the “Author” and “Subject” (c2) and “CC” (c3), and it would read the heading author, then set mdauthor to row 2, column 1, and do the same for subject and CC.
Any help on the syntax would be greatly appreciated. thank you in advance
To clarify. The sheet has metadata for files in the database and so the metadata is taken from the sheet and put in the custom metadata of all of the files.