Apparently there are Share menus everywhere on modern systems: OS X, Windows, Android, iOS. Everywhere, but not on Linux.

I often send different documents via Telegram and proper Share menu would be super handy. But since I couldn’t find any graphical way to do that I decided to write my own script for this very purpose.

That’s how Telegram looks when you try to send file via this command

To achieve that I have created a script, which accepts only one argument — a file path. Executing this script brings up Telegram window in “Choose recipient…” mode, where you can immediately type desired receiver name. A file will be sent as soon as Enter is pressed. No more Alt+Tab and drag and dropping. No more clunky file chooser navigation.

How to

You may need to install wmctrl as prerequisite. On Debian-based system it can be done using sudo apt install wmctrl

Now create the following two-line script

#!/bin/sh

telegram-desktop -sendpath "$(readlink -f "$1")"

wmctrl -x -a Telegram.TelegramDesktop

First statement resolves any provided path to an absolute path using readlink utility and then invokes Telegram passing a special flag. Second line asks your window manager to focus and activate Telegram window so you can immediately start typing recipient name.

Save this script to file at your favorite scripts location and apply chmod +x to it. Then to execute this script use

./tg-share-file.sh file-to-send.jpg

For convenience you may want to add it to your aliases by the name of, for example, tgsend

alias tgsend=/home/user/scripts/tg-share-file.sh

And invoke it anywhere like so:

tgsend vacation-photo.jpg

I would also advice considering integration into your favorite File manager if you need to send files or photos often. One handy shortcut may save you a lot of time otherwise spent dragging and dropping files. Just find a way to pass selected file path as argument to this script and you are good to go! But because there are myriads of file managers out there I leave this as an exercise for the reader :)