Choose a default directory with the <$browse> widget

Hi everyone !

I am trying to create a macro that help me insert image inside my tiddlers.

What I lack, is a way to choose a default directory with the <$browse> widget (currently, it seems it open the last directory I used to import, or something like that).

My current code is :

\define rename-import(new-name)
<$action-sendmessage $message="tm-perform-import" $param="$:/Import"/>

<$action-sendmessage $message="tm-rename-tiddler" from={{{[[$:/Import]links[]first[]]}}} to=$new-name$/>

<$action-setfield $tiddler=$new-name$ tags=[[Image]]/>
\end

\define image-block(image-name)
<$navigator>
<$browse />
</$navigator>

<$list filter="[[$:/Import]plugin-type[import]]">
<$button actions=<<rename-import $image-name$>>>
import
</$button>
</$list>

Image name : [[$image-name$]]
{{$image-name$}}
\end

<<image-block "plop">>

Btw, I don’t really undertand how the <$navigator> widget works, but it seems to do what I wanted. (I found it on this site).

Thanks !

1 Like

@dionisos nice implementation to avoid the import step, I tend to use <$browse multiple/>

I believe this is a security limitation of browsers, one we would all love to overcome. The issue is if the browser know and can access local file locations then it may be able to hack or extract things from the local device.

I have a work around I use in windows;

  • Store the “path” you want to access locally in your tiddlywiki
  • On the button you click to browse/upload make the first action to copy the “path” to the clipboard
  • If the open dialogue is not where you want it use ctrl-v in the filename field and hit enter
  • Now select your file

However I have published a workflow previously for Windows where when opening files I use a root folder in the Quick access, to select My top folder, then use the search to locate a file or folder.

1 Like

Thank you @TW_Tones !

So first, the upgraded version of my macros :

\define rename-import(new-name, tags-list)
<$action-sendmessage $message="tm-perform-import" $param="$:/Import"/>

<$action-sendmessage $message="tm-rename-tiddler" from={{{[[$:/Import]links[]first[]]}}} to=$new-name$/>

<$action-setfield $tiddler=$new-name$ tags="$tags-list$"/>
\end

\define image-block(image-name, tags-list)
<$navigator>
<$browse />
</$navigator>

<$list filter="[[$:/Import]plugin-type[import]]">
<$button actions=<<rename-import $image-name$ "$tags-list$">>>
import
</$button>
</$list>

Image name : [[$image-name$]]
{{$image-name$}}
\end

\define associated-image-block(image-name)
<$wikify name="image-improved-name" text="{{!!uuid}}-$image-name$">
<$wikify name="tags-list-choice" text="[[Image]] {{!!title}}">

<$macrocall $name="image-block"
    image-name=<<image-improved-name>>
    tags-list=<<tags-list-choice>>
/>

</$wikify>
</$wikify>
\end

So I just have to call <<associated-image-block “image-name”>> and I get section where I can upload an image which is automatically “associated” with the current tiddler. (the tiddler should have a field “uuid”, I did it, so I can rename of the tiddler and keep the association).

I use it in my journal tiddlers, because there are sections where I want to add images.

Now for my problem, I managed to add some directories in quick access on Firefox, on Arch Linux :
In “~/.config/gtk-3.0/bookmarks”, I added something like that :

file:///home/dionisos/dir1 dir1
file:///home/dionisos/dir2 dir2

So now I just have to click on the “browse” button, choose the directory where my pictures are, import, and that it :slight_smile:

2 Likes