Tinderbox Training Video 13 - Working with media in your TBX files (Part 2)

Tinderbox Training Video - Working with media (Part 2)

Level Advanced
Published Date 1/1/21
Tags Tinderbox, aTbRef, Export Code, Note Taking, value(expression), Audio, Images, Video
Video Length 08:32
URL Tinderbox - Working with media (Part 2) - YouTube
Example File TBX - L Working with media (Part 2).tbx (223.0 KB)
Revision 1
TBX Version 8.9

In this lesson, I expand on Tinderbox Training Video - Working with media in your TBX files (Part 1) and show to add captions and attribution (aka source) references to the media files you include in your Tinderbox files.

NOTE: If you want to play with the Action Code in this tutorial just download the example file linked above. It is all there.

TBX - L Working with media (Part 2)

Reference materials

Please rate this lesson, did you find it useful?
    • :grinning:
    • :neutral_face:
    • :confused:

0 voters

1 Like

Michael @satikusala , as usual this is very helpful. I tried to learn from you by outsourcing my media files (pictures at the moment) into a DEVONthink database, but I have a problem with the file name (or better: file path).
The way you show it in the video this is straightforward - a DT database on Google Drive, a directory within that, and inside the media file which you only need reference by file name.
When I try to copy that, however, I find that the path is not so straightforward - if I let the file in the DT database reveal itself in the Finder, the file is in a subdirectory called Files.noindex, then subdirectory png, then subdirectory 8, and only then the filename comes.
How come this is so much easier in your case?

Hey there.

I actually have NOT been storing my images in a DevonThink database, but rather have them stored on a folder on my hard drive. However, having said this, I did try putting an image in a DevonThink DB and am happy to report that the process works. :slight_smile:

The key is to find the path for the DT3 database. Rt mouse click on the img in DB3, click Get Info, and then copy the path. In my case, this results in “/Users/michaelbecker/Databases/Dissertation.dtBase2/Files.noindex/png/c/PerceivedCharacteristicsofInnovatingTheory.png”

You can then break up the elements into attributes:
MediaPath: /Users/michaelbecker/Databases/Dissertation.dtBase2/Files.noindex/png/c
MediaFileName: /PerceivedCharacteristicsofInnovatingTheory.png

MediaDIR won’t be necessary as DT3 does not appear to organize in this way.

You can then create you note in TBX. Here is a simple example: <img src="/Users/michaelbecker/Databases/Dissertation.dtBase2/Files.noindex/png/c/PerceivedCharacteristicsofInnovatingTheory.png" width="" height="">

I did not both to adjust the media width in this example:

Thanks, Michael, for the quick and comprehensive reply!
On second thoughts, there is no reason to put this into a DT database; putting it into a Dropbox folder seems more sensible, since I want to make things as easy as possible (because otherwise I will put fewer pictures into my TBX notes). This now means that I can put the whole media path into the Textexpander snippet and only have $MediaFile in the note itself.
By the way - the snippet works only up to the “>” after height. The bit that starts with the <br> has a problem and prevents text following the </br> from being displayed.
I cannot find the problem - when I delete that part, text after shows up in Preview without problem. Perhaps you can spot the problem - so here it is:
<br>^if($MediaCaption)^^value($MediaCaption)^endif^ ^if($MediaSource)^(Source: ^value($MediaSource)^)^endif^</br>
Many thanks!

Solved the puzzle - another caret was needed before the first endif! Now it computes without problems:

<br>^if($MediaCaption)^<b>^value($MediaCaption)</b>^endif^ ^if($MediaSource)^(^value($MediaSource)^)^endif^</br>

Yes, missing a ^ would certainly break things. I’m glad you figured it out.

Yes, you can inlcude the path in TextExpander, but I find it useful to have it in the TBXConfigNote, that way I have more flexibility to change it later.

1 Like

Just in case anyone is trying the method of keeping images in DEVONthink, and is using two computers, note that the same file may have a different path on each of the computers, although the DEVONthink item link will be the same.

For example, the same jpg file has the path
… Files.noindex/jpg/9/etc. … on my desktop, and
… Files.noindex/jpg/2/etc. … on my laptop.

I have no technical knowledge of the way DEVONthink does its work in its databases, but somehow I doubt there is a way round this. Unless there is some way of substituting a wildcard for the folder number.

1 Like

I’ll need to look into how the DevonTHINK item URL is constructed. I wonder if one can pull an ID number off the path and reconstruct the item URL.

How do you set width and height of the media in the code:

I can’t seem to find that specific info in Video 13. The rest of the info works well for me. I’ve got 3 months of radio recordings to upload into an archive, each needs a visual of a certain size. How can I set that size in Tinderbox?
Carolivia

1 Like

Hey there, here is my latest version of this code. For those that are new, this is export code being used in a note’s $Text. The same code can be used in a template. For various contextual process reasons in a project, I embed code in the text or in a template.

Width and Height are flags in an HTML tag. Standard HTML is this:

<img src=" " widith="x px" height="x px">

In HTML you can supply width or height alone and the browser will scale an image appropriately, or you can provide both values.

X = a number
px = pixels

Plus, you’ll note that I have the code put a caption label and caption under the image.

Example HTML generated by the code below.

<center><img src="/Users/michaelbecker/MyGDrive/DevonThinkTBXDB/Media/Article/MeetingOfWatersFuture.png" height="400"><br><b>Figure 5</b>: The Personal Data and Identity Market Meeting of the Waters: We Are Here  [@BeckerLauren2022] </center>

My Media Export Code

<center>
^if(^value($MediaFileName!=""))^^if(^value($URL!=""))^<a href="^value($URL)^">^endif^<img src="^if($MediaPath)^^value($MediaPath)^^else^^value($MediaPath("TBXConfig"))^^endif^^if($MediaDir)^^value($MediaDir)^^else^^value($MediaDir("TBXConfig"))^^endif^^value($MediaFileName)^" ^if(^value($MediaWidth!=""))^width="^value($MediaWidth)^"^endif^^if(^value($MediaHeight!=""))^height="^value($MediaHeight)^"^endif^>^if(^value($URL!=""))^</a>^endif^^endif^<br>^if($Caption)^<b>^value($CaptionLabel)^ ^value($CaptionNo)^</b>: ^value($Caption)^  ^if($CitationKey)^[^value($CitationKey)^]^endif^^endif^ 
</center>

NOTE: The spaces in the code matters.

Don’t let the conditions scare you, it just addresses all the element neededs to construct a valid image tag, if some values are not present then they’re not included.

Needed Attributes

The attributes you need are:

$URL - system attribute
$MediaPath - user generated attribute
$MediaDir- user generated attribute
$MediaWidth - user generated attribute
$MediaHeight - user generated  attribute
$CapationLable- user generated attribute
$CaptionNo - user generated attribute
$Caption- system attribute attribute
$CitationKey- user generated attribute

Aslo note, I use at TBXConfig not to hold universal values for my file, which I can overwrite with local values if I want to. For example, nearly all my image in a Media Diretory, and then put people in People, logos in Logos, article images in Artiles, so tweet $MediaDir in the prototype or in the local note. This allows me to make universal file management decisions easily. This is is hanled with the ^if()^expression^else^expression^endif^ syntax. Now, I could play around with Hook as an alternative, but I find that my current process works.

Ouput Examples

Here is what my note looks like:

In my markdown template this is what my output looks like:

With Pandoc and Chicago style this is what the output looks like:

If people are interested, I can create a video that hows how to address automated figure numbering

Hi Michael,

what’s the reason for splitting file name, path and folder into three attributes? Why don’t you use the $File attribute? This would allow you to click on the folder icon in the attributes pane, select the external graphic files and get back the full path to the image?

P.S.:
You could use this action code to extract the filename into a separate attribute:

if($File=="" & $FileIsModified==false) {
  $FileIsModified=true;
  $Fill="";
} else {
  if($File!="" & $FileIsModified==true) {
    $ImageFileName=$File.replace(".*\/(.+)","$1");
    $ImageName=$ImageFileName.replace("\.\w+$","");
    $Fill(original)=$PathFillImages("TBXConfig")+$ImageName;
    $FileIsModified=false;
  }
}

I use the $Fill attribute too to see the image in the map view. A Hazel script copies the image file into the support folder for fill images. $FileIsModified has to be set to true in the prototype. This attribute prevents the $Edict to run if nothing has changed.

From a tactical perspective, you’re right. This would be a direct and efficient approach. I too use fill and hover in all my image notes.

There is no right or wrong answer. It partly comes down to the process and what I’ve found to work. The process that I’ve found also let’s met have some flexibility in copying my templates to other TBX files–which include automated styling for citation types. It also reduced the reliance of regex (which I’m no great at). The process could get streamlined greatly if I could reliably pull the path from a Hook URL for instance; I’ve not been successful in doing this.

Hook still doesn’t work for you? Strange - no issues here… maybe we run a session again on this?!

It doesn’t work for me either… I get a hook URL ($URL) but $TheFilePath stays empty :confused:

the TBX file has to be saved before using the Hook action. You have to create the $TheFilePath yourself once (I use a prototype for that).

After those steps the Hook script does what it should do for me.

Is it possible to start the video at the right time with this method? I was only able to do this with VLC

Yes, you add this #t=startTime,endTime to the end of the source:

Example:

Update: if you want to link to a video on the web and not a local one on your computer use the sites, e.g. YouTube or Vimeo, embed code and add that to your TBX file. At the end of the string add ?start=90&end=200. These numbers are the number of seconds from start and how long you want it to play. Credit to @PaulWalters.

<iframe width="560" height="315" src="https://www.youtube.com/embed/5cfzSF3MEDY?start=90&end=200" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>

2 Likes

Thanks, it works great on the local server too!

  1. Is there an option to open the video in a new window?
  2. Which keys can be used to move through a video frame by frame?

No, TBX, due to macOS constraints for some time has not supported separate windows. It would be interesting to have the ability to have a tear-off preview window. I’ll ask.

No idea. Let us know if you figure it out.

Yikes. Preview stated out as, and still fundamentally is, a way to see what the (HTML) export is without actually exporting. Some users have leveraged this a way to have web-style formatted note 'visible in-app. I see why, but it is always going to come up short as there’s always some new edge case, as above, that whilst it might work in a (web) browser likely can’t/won’t in the browser-like internal preview window.

It’s worth asking why do you need frame-by-frame advance in Tinderbox preview. Given that you can easily do other things as the app window is in preview, the real reason is , I think still hidden. I don’t mean that you don’t need to review the video, but rather it’s not clear why you truly need to do it in the preview window.