How to launch batch scripts from TiddlyDesktop in linux?

327 views
Skip to first unread message

Mark S.

unread,
Jan 12, 2021, 3:13:00 PM1/12/21
to TiddlyWiki
TW Tones pointed out that it was possible to run scripts from TD in Windows.

When I try this, several different ways, in linux, it wants to edit the batch script, rather than run it. And yes, I do have the executable bit set on the file, the right extension (.sh in this case), and the path must be right because it can find the file for editing. 

Attempting to google "How to launch script from browser" leads me down multiple wrong rabbit holes.

Probably, if someone knows how to do this in Mac, it would be similar

Thanks!

TiddlyTweeter

unread,
Jan 13, 2021, 6:05:40 AM1/13/21
to TiddlyWiki
Ciao Mark S.

I'm not answering your Mac question as I'm only PC and Android.

What I did want to generally comment is that "residual" ability to access the OS via "in TW scripts" is still very worthy.
I think its particularly helpful in stand-alone one-file TW---AND TiddlyDesktop, which functions as a "whole".

Part of the issue is, of course, the browser lockdowns on security issues have made it very difficult to do that. 
But, FWIW, I was much taken by what Riz managed to do in the (previous) release on Timimi for Firefox. Essentially a small OS hooker that passed muster and let you launch scripts.

Frankly I do not have the competence to understand the machinations of the issue.

That said, I do have enough understanding to know that TW is much more than a static web page and OS interaction can more than ice the cake of it.

Thoughts
TT

Mark S.

unread,
Jan 17, 2021, 9:45:35 AM1/17/21
to TiddlyWiki
I was thinking in terms of intelligent web clipping. It's fairly easy to drag and drop an article into TW and import it. Unfortunately, the text will be in HTML, and the images will require an internet connection. So the resulting article is bulky, difficult to edit, and non-portable.

On Linux, in particular there are a lot of tools available. There's pandoc for file conversion, imagemagik for image conversion, and wget/curl for downloading. I was imagining that it might be possible to create a bash script that could leverage all this and be launched from within TW. So you could click on a button, and your article would be converted to markdown, the images downloaded, and the image links updated to the local resources. But all this is contingent on being able to run a script in the first place.

TW Tones

unread,
Jan 18, 2021, 2:44:52 AM1/18/21
to TiddlyWiki
MArk,

I do not recall the Linux method however if we "launch" a file in Windows it uses the application associated with the file extension to determine the app to load the file in. This can also be done with "start filename". However when in a command prompt does the name of a .exe .cmd or .bat result in that being executed. 

You can use a batch command of cmd /C command to forceful launch it in a command prompt and other methods.

I expect you just need to find the way to launch a script rather than edit it. Perhaps through a console session or something like that.

Tones

TiddlyTweeter

unread,
Jan 18, 2021, 12:06:42 PM1/18/21
to TiddlyWiki
Ciao Mark

Very interesting discussion---even though I'm Linux-impoverished.

Mark concluded ...
   |   But all this is contingent on being able to run a script in the first place.  

Right. And on that I'm no help. All I know is that when we worked on POLLY this issue came up and we were unable to settle it for Mac or Linux satisfactorily? 

The way that Windows evokes programs based on file-types (as mentioned by TW Tones) I don't think is so clearly mirrored on Linux?

Just FYI, in my own case, I now use Powershell on Windows (launched by a TW) to actually fetch remote files and then use PS to apply regex to prep them for TW. Partly I'm doing that so its a PORTABLE solution between PC's without needing to add utilities or learn how to pass commands to them. Powershell has a big range of functions that in some ways makes that kind of portability easier.

Just side thoughts
TT 

Mark S.

unread,
Jan 18, 2021, 1:30:32 PM1/18/21
to TiddlyWiki
I don't suppose you remember if there was a way to insert spaces? A sh script should always know to run itself, but if I could specify "/usr/bin/bash ....myshellscript.sh " that should force the system to invoke it correctly.

Thanks!

TiddlyTweeter

unread,
Jan 22, 2021, 5:14:22 AM1/22/21
to TiddlyWiki
Ciao Mark S.

I really looked into it. TBH I can't truthfully reply to your simple question.

Background: I using (mainly) Timimi to launch from TW (it is fairly complex & now retired in the recent version); TiddlyDesktop (fussy, mainly because it is Chrome inside?); BobEXE (very flexible on scripting; best of the batch; but overkill for most of my limited needs).

Outcome: too many variants to address your basic query simply.

Best wishes
TT

jwd

unread,
Jan 23, 2021, 1:04:23 PM1/23/21
to TiddlyWiki
What you may be looking for is the correct "Shebang" line at the top of the script that determines the interpreter to use (assuming the executable bit has been set.)

Typically I would use something like
#!/usr/bin/env bash
or, if you want to be specific
#!/path/to/your/systems/bash

The former will use the bash executable found first in the PATH of the environment of the TiddlyDesktop process; the latter would be preferred unless the script might run on systems where the path to the interpreter my differ, e.g., Macs have an old version of bash by default; while different Linux distributions' bash may be in /bin or /usr/bin.

HTH

Mark S.

unread,
Jan 23, 2021, 2:19:16 PM1/23/21
to TiddlyWiki
Thanks for replying! It does have the correct shebang, and runs fine from the command line. If I could include spaces in the file url, then I could run "/usr/bin/sh /path/to/my/script.sh". But I I don't know how to do that in a url line without converting to to %20 , which the OS wouldn't understand.

Dragon Cotterill

unread,
Jan 27, 2021, 1:47:15 PM1/27/21
to TiddlyWiki
Welcome to the wonderful world of Security Vulnerabilities and Work-arounds. Don't worry, this is my job.

OK, you need to register a new URL scheme handler. First create a Desktop Entry which specifies the mime-type. For example:

[Desktop Entry]
Type=Application
Name=TW Bash Script
Exec=twscript.sh %u
StartNotify=false
MimeType=x-scheme-handler/twscript;

Note that the %u passes the URL (eg. twscript://parameters%20here ) as a single parameter, according to the Desktop Entry Specification. https://specifications.freedesktop.org/desktop-entry-spec/latest/

Once you have created this Desktop Entry and installed it (put it in the local system applications directory ( ~/.local/share/applications/ or /usr/share/application/ ) then you must register the application with the MIME type (assuming you had named your Desktop Entry twscript.desktop

xdg-mime default twscript.desktop x-scheme-handler/twscript

Any script can then be added to the twscript.sh (make sure it's executable of course) and you can parse parameters just as any other script. The script should be placed anywhere in your executable path ~/.local/bin for example.

In the twscript.sh you'll have to add whatever parsing you need. You can't run separate scripts, but parameters are passed and can be checked and dealt with as appropriate.

Now, when an application finds the URL twscript:// it knows exactly what to do with it.

WARNING! This will make your system vulnerable to anybody who knows the MIME type that you have used. They could create a script which would execute on your computer. I would advise against this, but there you go.

Have fun,

Dragon.

Mark S.

unread,
Jan 27, 2021, 10:18:48 PM1/27/21
to TiddlyWiki
Thanks Dragon for the reply!

It doesn't work inside a node.js instance, but then I'm not sure it was supposed to. It does work from TiddlyDesktop, so that's great!

Re security, how do I back out these changes? It looks like maybe I just have to delete a line from ./.config/mimeapps.list ?? Otherwise, all the instructions talk about using xgb-mime uninstall, but I'm not sure that's the same thing since I didn't use xgb-mime install in the first place.

Also, if it can only be invoked from something like TiddlyDesktop running as user, how would the hacker gain access? Also, if someone can write to my drive and change the script, haven't I already been hacked? Just trying to understand the issues.

Many thanks again -- this was definitely not intuitive !

Dragon Cotterill

unread,
Jan 28, 2021, 4:04:37 AM1/28/21
to TiddlyWiki
Nah, using xgb-mime uninstall simply removes the actual software that changes the mime-types. Does nothing to remove the associations.
As you say, delete the entry from the mimeapps.list and it will stop the association (after a re-boot that is).

My warning about hackers is that the action can execute a script. Depending on how your script is written it may be possible to have very unintended consequences with allowing scripts to be run direct from a URL. The changes of this happening are extremely low though as the hacker will need to know what mime type and protocol you chose.

As to node.js, thats an whole 'nother kettle of fish.

Reply all
Reply to author
Forward
0 new messages