The native tinderbox://
url-scheme does most of the work for free,
but it doesn’t record the filepath of the active document.
(It was first conceived for linking within open documents, and any file not open or in the MRU list is hidden to it.).
SO
- We can usefully capture the
tinderbox://
url itself (possible through osascript in Tinderbox 8), but - we also need to append a
?filepath=<encodedurl>
option to it, whereencodedurl
is derived from the file path of the active Tinderbox document. - Because of this
?filepath
addition, which is outside the scope of thetinderbox://
scheme itself, we also need a HookOpen Item
script, to handle the document finding, giving it a suitable custom scheme name, perhapstbx://
For Name and Address, Hook now allows us to write a single ‘Get Address’ script which returns both Name and Addresss in a markdown [Name](Address)
format.
As the Get Address
script needs to percent-encode the file path, and the Open Item
script needs to decode that url-encoding, JavaScript may be a little more straightforward than AppleScript (JS has built in encode and decode functions).
For example, we can, first for the Open Item script:
- Enter
tbx
in theHook://
…document-identifier
field at the bottom of the Open Script panel in Hook preferences. - Paste in the whole code below, from the
//JavaScript
comment line at the top, which Hook requires to identify the script language, down to})();
at the end.
//JavaScript
(() => {
'use strict';
const
parts = "$0".split(/\?filepath=/),
tbx = Application('Tinderbox 8');
return (
tbx.activate(),
tbx.open(Path(
decodeURIComponent(
parts.slice(-1)[0] // Document filepath.
)
)),
Object.assign(
Application.currentApplication(), {
includeStandardAdditions: true
}
).openLocation(
`tinderbox://${parts[0].split('//')[1]}`
)
);
})();
and then for the Get Address script.
Paste the the whole of the following (again, including \\JavaScript
at the top, down to })();
at the end.
//JavaScript
(() => {
'use strict';
const ds = Application('Tinderbox 8').documents;
return 0 < ds.length ? (() => {
const
doc = ds.at(0),
note = doc.selectedNote();
return null !== note ? (
`[${note.name()}](${
'tbx' + note.attributes.byName('NoteURL')
.value().slice('tinderbox'.length) +
'?filepath=' + encodeURIComponent(doc.file().toString())
})`
) : '';
})() : '';
})();