pyautogui - copying selected text - pyautogui

After manually selecting text in a browser window, I'd like to be able to use a hotkey to a .py file to copy the selected text to the Windows clipboard.
Have tried
pyautogui.hotkey("ctrl", "c")
and
pyautogui.keyDown('ctrl')
pyautogui.press('c')
pyautogui.keyUp('ctrl')
But neither works. From trying to troubleshoot this in a .ipynb (Jupyter notebook) file, it seems the issue is Window focus. If I do:
time.sleep(2)
pyautogui.hotkey("ctrl", "c")
And manually alt-tab from the code editor to the browser window with selected text, it works fine. Trying to automate the alt-tab doesn't seem to work b/c the alt-tab window stays on screen instead of briefly flashing the way it does when manually executed.
pyautogui.hotkey("alt", "tab") # alt-tab
time.sleep(2)
pyautogui.hotkey("ctrl", "c") #copy
So how can I select text in a browser window and then run .py file via hotkey but have the Window focus switch back to browser window before pyautogui.hotkey("ctrl", "c") executes?

Related

Ctrl-N in emacs keybindings for Jupyter notebook in Chrome

I'm using Jupyter notebooks in the Chrome browser. I've installed nbextensions and am using the emacs keybindings. Most keys work as expected, even those that conflict with Chrome shortcuts, like ctrl-P. But ctrl-N still opens a new window. I've tried Shortkeys, with which I can set ctrl-N to "do nothing", but it is not passed through to the notebook. I tried AutoControl Shortcut Manager and have the same problem.
Old answers to this question say that you can't override ctrl-N at all, which is no longer true in the newer versions of Chrome, but how do you stop the default behavior and allow the key to pass through to the page?
You can do this with AutoControl Shortcut Manager by using the SYNTHESIZE INPUT action to send a synthetic Ctrl+N from the inside of the webpage.
That way, the webpage will respond to the shortcut but not the browser.
This is how you do it:
Set Ctrl+N as the trigger
Choose SYNTHESIZE INPUT as the action and enter the keystroke Ctrl+N
Select option Send from the inside of webpage
Now, whenever you press Ctrl+N, Chrome will do nothing, but the webpage will receive the keystroke and will react to it.
Of course, you'd only want to do this on those Jupyter Notebook pages, so make sure you add a URL condition to that trigger.

How can I move focus from any other tool window to text editor in PhpStorm?

For an example after I go to the Project tab with Alt+1 shortcut and open specific file with pressing Enter I then want to go and edit content with single shortcut. Is there any way to do it?
There is couple of things that I can use, but neither does exactly what I want:
Ctrl+Tab - that opens the switcher and selects next file in switcher instead of allowing me to edit file with single Ctrl+Tab
Ctrl+E or Ctrl+Shift+E do different things but basically the result is simmilar as above
What I want is to simply edit the file after opening it with keyboard from Projects tab (without using mouse).
How can I move focus from any other tool window to text editor in PhpStorm?
Just press Esc key.
Works in every tool window. For built-in Terminal though you can (may have to) configure different shortcut for such action (as Esc can be needed there).
For an example after I go to the Project tab with Alt+1 shortcut and open specific file with pressing Enter I then want to go and edit content with single shortcut. Is there any way to do it?
Use F4 for that (action is available in context menu and called Jump to Source).
Ctrl+Tab - that opens the switcher and selects next file in switcher instead of allowing me to edit file with single Ctrl+Tab
Just press and release it quickly: it works just like Alt + Tab on Windows. If you keep modifier key pressed (Ctrl in this particular case) it will keep the Switcher window opened.

How to switch to source code in PhpStorm?

I want to be able to quickly switch to the code editor window in PhpStorm. I've found "jump to source" hotkey, but it works that way: if I have some folder selected in my directory tree ("Project", on the left side) and I use the hotkey (F4 by default) I won't get switched. Also, if some other file has been selected in directory tree I'll get switched to the code of the selected file. However, I just want to emit clicking on the editor field using mouse. Just switch.
However, I just want to emit clicking on the editor field using mouse. Just switch.
Just Esc -- that's it.

don't restart from beginning when searching text

I looked in the settings but apparently Sublime Text doesn't have an option to disable the restarting from beginning when doing a search.
I want that SB stops at the end of file when he finished searching
When you open the Find bar with CtrlF (⌘F on OS X) there is a button to "wrap" the search:
If the button is not selected (as shown above), then Find will stop at the end of the file, and not "wrap" back to the beginning. This option is also available in the Replace dialog as well.

Open HTML file in non-default browser

I know how to do that manually. But, is there an option to set up one particular file to be opened always in Chrome, despite Firefox being the default browser.
What I want is to set up somehow, one HTML file on my desktop to be opened in Chrome, but the rest of the html files continue to open in Firefox, and I want this to apply always for this file, even when I move it to some other computer.
I will assume we are talking about the Windows OS first. Secondly, I will assume that you do not have a Chrome shortcut sitting on your desktop, if you do have a shortcut just skip to the second step otherwise continue reading on.
Step 1: Create a Chrome Shortcut
There are many ways of doing this. Simplest one is to just search for Chrome in the Start Menu and drag the shortcut to your desktop like I have in the picture below.
Step 2: Open the Shortcut Properties
Right click on your Chrome shortcut and click the Properties option, like in the image below.
Step 3: Edit Your Shortcut's Target Value
Find the Target option in the Shortcut tab of the Properties window. Add the following piece of code at the end of your target statement.
--app=https://example.com
Replace https://example.com with any website you like. In the image below the highlighted part shows where you have to edit the target value. I have made a shortcut for https://google.com.
Hope this helps!
Note: This is a Chrome specific trick and it will open a new window without a URL bar or a toolbar.
Edit: Added pictures with more description.
You can right click on the html file then got to open with and it should display the available browsers select the one you would like to open the file with
You should be able to set it to open (in Windows (7) ) by right-clicking on a html file, going to 'Open With' and 'Choose Default program':
on most Linux systems you should be able to right-click, go to 'Properties' and set it under 'Open With...':
also, in Google Chrome settings you should be able to set it as default: