How to bind keyboard shortcut to run command on selected file in linux? - linux

I know how to set a keyboard command shortcut, that's easy, I just go to Applications > Settings > Keyboard and then click the Application Shortcuts tab within my Manjaro Linux system and set whatever command to whatever shortcut.
But how can I make it run that command on a selected file or selection of files?
Is there something I can change or add to the command to make it run on the file or files currently selected within my XFCE desktop environment?
Thanks!

Your approach would require to correlate your mouse position to your desktop and file-manager. Then you would need to have knowledge of the internal state. You then would need to display some GUI. This way of thinking in regards of programing is seriously wrong.
What you are looking for are context menu actions. So keep it that way.
You have files on your desktop or in the file-manager and can call user defined actions on one or more files. I think XFCE had something like Thunar. You may use caja wit caja --no-desktop and create some actions with caja-actions-config-tool. Gnome still has it, if you prefer Nautilus.

Related

Assign Keyboard shortcut per application in Linux Desktop Environment

I would like to inquire if there is a program in Linux that we can use to assign new keyboard shortcut per application. For example, if I'm in FeatherPad I would like to assign Super+S to save. If I'm in terminal, I would like to use Super+V to paste.
Or a program that cab map/assign new shortcut and translate that to an existing shortcut. If in terminal I can paste with Shift+Insert then I would like to map Super+V to Shift+Insert
The closest analogy would be a program like Autohotkey in Microsoft Windows. How do I do this in Linux Desktop environment regardless it is Gnome2/Unity/XFCE etc. ?
There used to be a way to do this called "custom accelerators" or "editable accelerators". It used to be supported in GNOME 2 and XFCE (maybe in others). But since the move to gtk3, this functionality seems to have been removed in GTK-based desktop environments.
In KDE/Plasma, you can use System Settings -> Shortcuts -> Global Shortcuts and then the plus symbol to add specific shortcuts that only apply to certain applications, but unfortunately, not all applications support it.
In FeatherPad itself, there should be Options -> Preferences -> Shortcuts, but I've had no luck getting it to register any shortcut consisting of just Super and a key.
I'm unfamiliar with Autohotkey but it seems that AutoKey is sometimes mentioned as an alternative on Linux?

alt-tab like functionality when using terminal?

When working in GUI we do alt-tab (or cmd-tab in mac) to switch between multiple programs, for example I am writing a text file in a text editor and then I do alt-tab to switch to already running browser to google up something then I alt-tab again to come back to keep editing.
How do you perform such "switch between" programs in command line interface - for example working with a ssh command line shell?
EDIT: I forgot to mention it, I am using ssh to connect to my university's server, and they don't have screen & tmux installed, and my account have no right to install any new apps... Is there any built-in functionality to perform this task, or any work around? For exmaple can I "minimize" running proggram and come back to regular shell interface, do some work, then display the "minimized" process again?
Another workaround: use the shell's job control, eg if you're editing a file, CTRL-z pauses the editor and brings you back to the shell, where you can compile, see manpages, browse the web or whatever -- and of course you can background the browser or anything else.
Screen command offers the ability to detach a long running process (or program, or shell-script) from a session and then attach it back at a later time.
As a crude workaround, run multiple terminal windows on your computer, and alt-tab between them.
Incidentally, at the Linux console, you can switch virtual terminals with ctrl+alt+F for at least F1 through F6, commonly F8 or more (depends on how the distro sets them up). Not your case, I know, but in case future visitors should benefit.
If you are comfortable in Emacs, it allows you to run multiple independent ansi-term buffers.
You can also use "GNU screen" to emulate multiple terminals in one terminal.

Execute batch-file from browser

i have got a batch-File. I mostly have to execute it when i'm in my browser (Firefox).
So i dont want to go to the directory and execute it. I want to have something in my browser.
First i thought about making a firefox-add-on. Something like a button, which executes my batch-file. But I failed.
Then i made a bookmark to the file, but it only shows me the content of the batch-file.
Is there any other option to execute a batch-file from the browser?
EDIT: I have found an add-on that creates an button to execute files:
https://addons.mozilla.org/de/firefox/addon/external-application-button/
I don't know a way you can run this from a browser, but perhaps you don't need to. I'd create a global keyboard shortcut. You haven't mentioned your OS so I've assumed Windows.
Go to your desktop, right-click and select New > Shortcut.
Browse to your .bat file.
Name the shortcut whatever you like - probably best to use yourfile.bat shortcut or similar.
Right-click your newly-created shortcut and select Properties.
On the Shortcut tab, click into the Shortcut key area.
Press Ctrl+Alt+B. I've used B for bat - you can use what you like, although some shortcuts may be used already in your browser - test and adjust if necessary.
Click OK - you're good to go!

How can I open nautilus with given location with selection

We can open Nautilus with given directory in Terminal like:
nautilus /home/jeeeyul/workspace
However, I want to open "/home/jeeeyul" and select "workspace" and reveal it rather than open "workspace" directory.
Can I do this from Terminal?
I do not know if this was recently added but you can open a folder's parent and select it using the following method:
nautilus -s /home/jeeeyul/workspace
This will open nautilus in the /home/jeeeyul/ path and with the workspace folder selected.
Just wanted to add this in case anyone else was still searching for a solution.
Nautilus can open the parent folder of workspace, but includes no option to control selection.
The only possible option I can think of is xdotool, which can emulate mouse and keyboard events within a window.
For mouse, if you can predict where the workspace icon or list item will be located within the Nautilus window, you can open the window with specific dimensions using --geometry, then use xdotool to cause a mouse click at that location. If you have trouble predicting the location, you can perhaps rename workspace to something that will appear at the top of a list, and have Nautilus sort items by name ... then rename it back after the click.
Keyboard might be a better option. You could use xdotool to send keyboard commands and/or type things in the Nautilus window that would force the selection. You'd need to experiment as to how. (I don't know what version of Nautilus you're using, or what other files might be in that folder.)
These solutions are hardly ideal. With any luck, someone else with more in-depth knowledge of Gnome will post something exceeding clever.
Yes, you can do this using terminal. After you start terminal, you have to switch user you can use sudo -i for switch as root user and then use nautilus.

Can I assign custom keyboard shortcuts for menu items in applications on Ubuntu?

OSX allows user to add custom keyboard shortcuts for menu items. For instance you can define a custom keyboard shortcut for "Copy" and it will work for every application that has a menu item called Copy.
Is there a way to do this for GTK and/or KDE applications?
For KDE applications, it is possible for common keyboard shortcuts. To do this, open systemsettings and navigate to Standard Keyboard Shortcuts.
For example, here I change the shortcut for "activate next tab" to Ctrl-Tab (for consistency with Firefox):
This changes the shortcut in most tabbed KDE applications as well as tabbed dialog boxes. You can specify up to 2 alternative shortcuts for each action.
However, this only works for common shortcuts; you can't globally specify shortcuts for arbitrary menu-item captions.
I don't think GNOME applications have any such feature. You have to change the shortcuts individually (for each application). (Generally KDE is more customizable.)
Is there a way to set an absolute keyboard shortcut for an arbitrary menu item name that will be honored by any GTK+ application?
No.
Can you set a different global shortcut for Cut/Copy/Paste?
I suspect so. I didn't do the reading, but here's two promising links: making keyboard shortcuts in linux as uniform as the mac and change default/preference keyboard shortcuts like copy & paste
You can of course modify GTK+ applications to tweak their shortcuts. In the case of a GTK+ application whose GUI was designed with Glade, e.g. virt-manager, this could be ridiculously trivial.
I suggest you to take a look at xbindkeys and xdotool. Those are the automation tools which can help you to simulate certain keystrokes with customized shortcut.
By this means, though you don't really modify the original shortcuts, but you can still make your desired key combinations functional.

Resources