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

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.

In some training videos, the instructor performs the action so quickly that you can only figure out how to do it if you watch it frame by frame

1 Like

If you use the macOS viewer, you can quickly press and release the Play key (where the F8 key is), and if you use Stamp to start VLC:

runCommand("/Applications/VLC.app/Contents/MacOS/VLC " + $fullPath + $startSec);

you use the E key to move frame by frame

@Data Here is an answer to your last two questions: Tinderbox Lesson - Embedding and Previewing Video in And Out of Tinderbox.