I'd love to be able to select file(s) in some android app (e.g. pictures in gallery, or recordings) , then select "share with" and select "termux" and one of scripts from the list configured to receive files via "sharing". I'd love to be able to make such script to receive "shared with it files" via arguments.
(I am not sure if it's feature request appropriate for temrux-app or termux-widget or maybe request for even new app. I just would like to be able to process files with my scripts easily via sharing UI flow, instead of writing files into directory and then running script. It would be wonderful if I could share multiple files at once!
Maybe sth like $HOME/bin/termux-url-opener , but for files? (Now I am getting "save in directory" dialog for files)
What you're looking for is basically a way of handling Android Intent events using scripts inside of Termux. As of now there is no way of doing so that I'm aware of. However, there is permissions limited access to the 'am' and 'pm' Android shell tools that can be used for sending new Intents but not for receiving Intents AFAIK. If you want to be able to handle incoming Intents then you would need to update the app manifest file (AndroidManifest.xml) for Termux to add the right intent filters, as well as have some way for Termux to pass those Intents on to your script.
I don't see a way of doing what you're asking for as of now but such a feature _might_ be possible to implement.
There is termux-file-editor, which was added at the same time as termux-url-opener
From changelog:
Termux can now receive files shared from other apps. Files are saved into ~/downloads/ and it鈥檚 possible to open this folder or editing a file directly when receiving it. Editing is done through a ~/bin/termux-file-editor program which will be called with the newly received file as only argument.
Is this what you're looking for?
Yes and No.
Yes, for one file awesome -> Wow! termux-file-editor sounds awesome!
I got misleaded by "save file" dialog. (Maybe adding "?" in "save file" dialog , mentioning after click that "termux-file-editor" can be called would be an option? Or I was just before "RTFM" :) )
No, it does not handle multiple files -> It serves only part of my needs. I would love to be able to send multiple files and let them be opened either via multiple arguments to program (those could be temporary streams), either via file with list of file locations, or any other way.
Thanks a lot for feedback Neo-Oli ! :D
I confirm:
my ux idea for multiple files:
~/bin/termux-files-editor (or other bin/something of choice)I have a Python2 script, and I would like to send an URL to it with the Share function over Termux.
What is the prefered syntax of the $HOME/bin/termux-url-opener file?
I tried two methods, but haven't luck.
1st method: create a termux-url-opener script with the following line:
python2 ~/myscript/myscript.py %1
The script started, but didn't get the %1 parameter.
2nd method: create a symlink to my script. It can't running, because the python2 parameter is missing from it.
How is it possible to pass a URL parameter for a Python script with the Termux Share function?
@sanchomuzax
The script started, but didn't get the
%1parameter.
You expand variables with $, not %.
Or, the more elegant way:
create a symlink to my script
You'll need a shebang on your script to specify an interpreter to run the program (in this case, python2). Add this to the beginning of your script so you can call it directly:
#!/data/data/com.termux/files/usr/bin/python2
(Or wherever location python2 is installed)
Thank you, solved. 馃憤
Most helpful comment
There is
termux-file-editor, which was added at the same time astermux-url-openerFrom changelog:
Is this what you're looking for?