Configurable keyboard shortcut without using content scripts - google-chrome-extension

Chrome Extension: I am looking for a way to assign global keyboard shortcuts that can be invoked even when the current tab has no content (and hence no content script). Some examples of such tabs: 'new tab' tabs, chrome://extensions tabs, 'page not loaded' tabs, etc Use cases for such a requirement are operations like close tab, go to next/prev tab, etc.
The chrome.commands api allows one to do this. However, there seems to be no way for the user to configure these keyboard shortcuts, which is something I'd really want my extension to allow.
Is there any way to get configurable keyboard shortcuts that don't need a content script?

The shortcut for chrome.commands cannot be changed by the extension, but it is configurable by the user. This interface is built-in and offered by Chrome itself.
Visit the extensions page, scroll down and click on the Configure commands link. A box will be shown, where the user can set the preferred shortcut:
The code for the "Remap shortcut" extension is posted in this answer.

Related

What keyboard shortcut can i use without conflicts with modern browsers?

I'm developping a web application and i intend to use mouse and some keyboard shortcuts, and if possible, use modal keys (Ctrl / Shift / Alt).
I've noticed a lot a conflicts with modern browsers/OS. Here are some examples you may know:
Ctrl+S
Ctrl+F
Shift+R : refreshes the page on firefox
Alt+left click : moves a window on linux
Ctrl+J : opens the download tab in chrome
I can't find what shortcuts (with modal keys) i can use safely in my application. Is there a list somewhere of a rule to follow?
You could have a look at this, which is a rather exhaustive list of used shortcuts.
However your question has already been asked here and here and it seems there is no such list.
Try this:
http://en.wikipedia.org/wiki/Table_of_keyboard_shortcuts
My suggestion would to throw something unique in the shortcut for example:
Say you needed to bookmark something quickly, chromes is ctrl+D, instead i would do ctrl+shift+m or ctrl+alt+m
Even still you might run into duplicate shortcuts, but going with something unique will give you the best results.
Hope this helps.

Entering omnibox-mode programmatically

I want an extension to be controlled by the Omnibox. The chrome.omnibox API lets me register a keyword, but that means a lot of clicking or typing to get to the extension. For example, I have to Ctrl+L to select the omnibox, then type some letters for the extension and space/tab.
Can this "omnibox mode for my extension" be entered programmatically? I.e. is there an API call I can make that will take the user's keyboard focus to the omnibox in already switched mode to my extension? I just want to replace the sequence of clicks/typing with a single keyboard shortcut that will allow the user immediately interact with the extension via the omnibox.
This is not currently possible. I could see this being implemented in two ways:
1. As you suggest, by allowing the extension to enter omnibox programmatically. I'm not sure if that's a good idea - stealing keyboard focus could be annoying to the user, and a possible security risk.
2. By adding "enter omnibox mode" as a target for the commands API. That way the user can configure the keyboard shortcut or disable it entirely.

Feasibility of grouping tabs in Chrome

I'd like to be able to group tabs in Chrome (on Windows Vista/7 primarily), as I can with Tab Mix Plus on Firefox, so that I only see one group in the tab list at one time. I don't seem to be the only one, but it hasn't been done, so far as I can tell. There are plenty of tab managers out there, like TooManyTabs and Tab Outliner, which summarise, save and unload tabs, but they don't leave them loaded whilst hiding them.
I've not coded a Chrome extension before, but I think the specific problem is that you can't control the visibility of tabs (in the way you can with the hidden attribute of tabs in Firefox) or windows from a Chrome extension. Is that right, or have I missed something in the API?
If that is right, any way anyone can see to hack round this? Put the tabs I want invisible in a window and then use whatever Windows API allows http://www.hide-window.com/ to hide that window?

Can I hide my extension's icon by default?

My Chrome extension doesn't need an icon - it's a one-liner extension that doesn't want to take up space on your extension bar.
How can I hide the icon by default?
Due to a change spearheaded by Google, all extensions now must have an icon in the toolbar area or the "overflow" in the menu.
Even if you don't have a browser_action, your extension will display an icon (or failing that, a tile with extension name's first letter). If you do not declare a browser_action, it will be greyed out and non-interactive, but will still be there.
The idea of this change is to provide visibility of otherwise potentially stealthy extensions ("Hey user, did you even know you have those installed?"). It's, let's put it, debatable whether it's the best approach, but that was Google's decision.
To suppress this behavior, add "converted_from_user_script": true to the extension's manifest.json. This works as of Chrome 61.
It used to be that visiting a link to a user script (ending in .user.js) caused Chrome to package up the user script as a content script extension with a generated manifest which included the converted_from_user_script key. Of course, this no longer works because all extensions (except in developer mode) now have to come from the Chrome Web Store.
Google thought it best to make the icon mandatory and I think so too, for reasons already pointed out by Xan.
Now of course you 're right, when you say that many extensions have no need for an icon, but the requirement of one still gives your extension an identity and Google still gives the user the opportunity to remove it from the toolbar. He simply has to right click the extension's icon and then choose Hide in Chrome menu.
I know, many users don't really bother to read all of the options under right click, or even right click it at all. But most of them still will make a single left click, to see if there is any option in the fancy new extension they added. You can take advantage of this by making a simple window where you point out their option of hiding the icon.
If you don't want an icon, you can omit the browser_action parameter from your manifest.json (the default_icon option is where you usually specify the icon). The browser_action section is what controls what you see in the toolbar.

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