The trick of a Copy As script is to place something in the clipboard in the same format that Tinderbox uses for copying and pasting notes.
As you know, the clipboard can simultaneously hold its data in several formats, and the format eventually used is decided at paste-time, depending on the capacities and preferences of the receiving app.
When you copy a note in Tinderbox 8, a clipboard object (labelled with the type com.eastgate.tinderbox.scrap
) is created in a .tbx XML format.
A sample might look like this:
Sample clipboard XML
<?xml version="1.0" encoding="UTF-8" ?>
<tinderbox version="2" revision="12" savedBy="version 8.1.0 b405" uuid="CDCDD0A2-9B80-49EA-B2B6-22973D1A60F3" >
<item ID="1571687918" Creator="Robin Trew" proto="Reference" >
<attribute name="Abstract" >abstract :: The publication’s abstract as plain text.</attribute>
<attribute name="ArticleTitle" >Sample of :: Journal article</attribute>
<attribute name="Associates" ></attribute>
<attribute name="Authors" >LF., authors :: The publication’s authors. Separate names with</attribute>
<attribute name="Created" >2019-10-21T20:56:56+01:00</attribute>
<attribute name="DominantLanguage" >en</attribute>
<attribute name="ISBN" >isbn :: The publication’s ISBN.</attribute>
<attribute name="IsComposite" >false</attribute>
<attribute name="Issue" >optionally followed by the issue number in parentheses</attribute>
<attribute name="Journal" >journal :: The publication’s journal.</attribute>
<attribute name="Modified" >2019-10-21T20:57:17+01:00</attribute>
<attribute name="Name" >Sample of :: Journal article</attribute>
<attribute name="Pages" >pages :: The page range in the hosting publication (e.g., a book or periodical) this publication was published in.</attribute>
<attribute name="PublicationYear" >1971</attribute>
<attribute name="RefKeywords" >keywords :: The publication’s keywords. Separate keywords with LF.</attribute>
<attribute name="RefType" >JOUR</attribute>
<attribute name="ReferenceRIS" >TY - JOUR
AU - LF., authors :: The publication’s authors. Separate names with
T1 - Sample of :: Journal article
KW - keywords :: The publication’s keywords. Separate keywords with LF.
PY - 1971
JA - journal :: The publication’s journal.
SP - pages :: The page range in the hosting publication (e.g., a book or periodical) this publication was published in.
VL - volume :: The volume number of a journal article
IS - optionally followed by the issue number in parentheses
SN - isbn :: The publication’s ISBN.
AB - abstract :: The publication’s abstract as plain text.
N1 - notes :: The publication’s notes. Separate paragraphs with LF. Separate notecards with LFLF.
UR - url :: The publication’s default URL (Uniform Resource Locator).
ER -
</attribute>
<attribute name="ReferenceURL" >url :: The publication’s default URL (Uniform Resource Locator).</attribute>
<attribute name="SelectionCount" >9</attribute>
<attribute name="URL" >bookends://sonnysoftware.com/38460</attribute>
<attribute name="Volume" >volume :: The volume number of a journal article</attribute>
<attribute name="Xpos" >0.09521484375</attribute>
<attribute name="Ypos" >-0.4613037109</attribute>
<text >authors :: The publication’s authors. Separate names with LF., ‘Sample of :: Journal Article’, journal :: The publication’s journal., volume :: The volume number of a journal article (1971), pages :: The page range in the hosting publication (e.g., a book or periodical) this publication was published in.
</text>
</item>
<links >
</links>
</tinderbox>
So there are two things to do:
- Build your XML string, with the AttributeName::Value pairs that you need.
- Place that XML in the clipboard, not as
public.utf8-plain-text
but as com.eastgate.tinderbox.scrap
We can put things in the clipboard, labelled with their type, by writing JavaScript for Automation code like:
ObjC.import('AppKit');
// setClipOfTextType :: String -> String -> IO Bool
const setClipOfTextType = utiOrBundleID => txt => {
const pb = $.NSPasteboard.generalPasteboard;
return (
pb.clearContents,
pb.setStringForType(
$(txt),
utiOrBundleID
)
);
};
setClipOfType('com.eastgate.tinderbox.scrap')(strXML)
(where the AppKit import is needed to get access to the $.NSPasteboard object)
PS You should be able to skip any potentially irrelevant XML tags, like those which specify creation or access date.