How to map a global key to refresh? - firefox

Winamp has a neat feature. Global keys. That way I can change the playing song even if Winamp GUI doesn't have focus.
I am looking for a similar solution to Firefox or Chrome.
I use Eclipse to code PHP.
It auto SSH's and saves to another machine (testing)
I could use something like XRefresh with a mapped virtual drive but I cant install Samba on the testing machine.
Right now I have to:
CTRL+S (save and auto-update)
ALT+TAB (switch to Firefox GUI)
F5 (refresh current Firefox page)
ALT+TAB (back to Eclipse)
I am looking for something like:
CTRL+S (save and auto-update)
CTRL+X (refresh Firefox - while keeping focus on Eclipse)
I've looked over Firefox Plug-ins but found nothing to my needs. Chrome neither. XRefresh would be a perfect solution but, as said, cant SSH/Samba into the testing machine.

Autohotkey
Let me add my result for the awesome.ahc file:
^s::
SetTitleMatchMode, 2
IfWinExist, Mozilla Firefox
{
WinActivate, Mozilla Firefox
ControlSend, ahk_parent, {F5}, Mozilla Firefox
}
Return
This will switch to firefox and refresh the currently active tab.

As demoncodemonkey greatly suggested you can use Autohotkey. This is my script sample.
^x:: ; listen for a CTRL+x
Send ^s ; sends a CTRL+s save command to Eclipse
Sleep 500 ; sleeps a bit to allow SSH to transfer file
Send !{tab}^r ; alt-tab followed by a browser refresh
Sleep 100 ; firefox, needs just a bit to allow ALT-TAB
Send !{tab} ; tabs back to eclipse
This is even better than I had in mind as I can do it all with only a single command. Very impressive. Thanks again demoncodemonkey.

Using Frankie's answer, I developed something a bit more advanced. My editor is Aptana, but you can easily change it into anything else:
$^s:: ; only capture actual keystrokes
SetTitleMatchMode, 2 ; match anywhere in the title
IfWinActive, Aptana Studio 3 ; find aptana
{
Send ^s ; send save command
IfWinExist, Mozilla Firefox ; find firefox
{
WinActivate ; use the window found above
Sleep 500 ; sleeps to allow SSH to transfer file
Send ^r ; send browser refresh
WinActivate, Aptana Studio 3 ; get back to Aptana
}
}
else
{
Send ^s ; send save command
}
return

Related

How to switch between Chrome windows in Powershell?

I am writing a powershell script that goes through 3 chrome windows (not tabs, these windows are on 3 different monitors) and want to refresh every window.
I cannot figure out a way to switch between windows.
I have the following code:
while(1) { # Loop forever
sleep -Seconds 15 # Wait 15sec
$wshell = New-Object -ComObject wscript.shell
if($wshell.AppActivate('Chrome')) { # Switch to Chrome
Sleep 1 # Wait for Chrome to "activate"
$wshell.SendKeys('{F5}') # Send F5 (Refresh)
} else { break; } # Chrome not open, exit the loop
}
This only refreshes one page. I tried to use
[System.Windows.Forms.SendKeys]::SendWait("%+{ESC}")
to switch between apps, but since there are other open apps it is not possible.
Is there a way to switch between Chrome windows? Haven't found any shortcuts or solutions.
Thank you!
Add this before your refresh:
$wshell.SendKeys('^{%TAB}'); # Performs an Alt + Tab to switch windows
Of course this implies ONLY chrome windows are open
Since multiple programs are open you could give this a shot:
($wshell.AppActivate((get-process chrome).MainWindowTitle))
If you are looking for a shortcut, try this:
If Chrome icon is on the first place (leftmost) on your taskbar, press Win + 1 TWICE to switch to the second window, press Win + 1 three times to switch to the third window.
About emulating Win key in Powershell, the simplest way is Ctrl + Esc; but it doesn't work as Win + x combination. This answer may help: https://stackoverflow.com/a/51868925

Passing alt-tab to Emacs inside Screen inside Putty

I run terminal-mode Emacs (using the -nw option) inside Screen on my office Debian box. This way, I can log in my box with ssh from anywhere and work even with slow or intermittent connection.
When I log in from Windows using Putty, I miss the possibility of using the Alt-Tab key combination (M-TAB in Emacs parlance). I compensate using the two keys Esc and Tab, but that's two key presses, which is slower.
I just discovered that using Autohotkeys I can make Ctrl-Tab do the same as Alt-Tab with this rule:
LControl & Tab::AltTab
and I can disable Alt-Tab altogether with this other rule:
!Tab::Return
but this is not what I want. I need to copy the functionality of Alt-Tab on some other hot key (Ctrl-Tab is okay and the first rule does that) and additionally I want the Alt-Tab key to be passed to Putty when I am using it (which would pass it to Screen, which would pass it to Emacs). In other words, Alt-Tab should not be disabled, but its special meaning should be deleted.
Is this possible with Windows?
While I don't fully understand the issue you're encountering, this framework should give you something to work with for conditional actions based on the window.
!Tab::
{
WinGetTitle, Title, A
if (RegExMatch(Title, "PuTTY.*"))
{
; Do something if PuTTY is the active window.
}else{
; Do something else if PuTTY is NOT the active window.
}}
Working with the answers I got from several hepful users, I got to the final solution I have used for some time now. Here is the Autohotkeys script that I put on my desktop and that I double-click every time I have to restart Windows:
File "alt-tab to ctrl-tab.ahk"
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
LControl & Tab::AltTab
; !Tab::Return
; #IfWinActive, putty
!Tab::send {Esc}{Tab}

WinActivate not working in autohotkey script

I have the following AutoHotKey script to help me switch between different open apps, using a shortcut:
^!c::ToggleWindow("Chrome")
^!p::ToggleWindow("PowerShell")
ToggleWindow(TheWindowTitle)
{
SetTitleMatchMode,2
DetectHiddenWindows, Off
IfWinActive, %TheWindowTitle%
{
WinMinimize, %TheWindowTitle%
}
Else
{
IfWinExist, %TheWindowTitle%
{
WinActivate
;;; Tried using WinMaximize/WinRestore here but same result
}
Else
{
DetectHiddenWindows, On
IfWinExist, %TheWindowTitle%
{
WinShow
WinActivate
}
}
}
}
The problem is that for some apps it works only sometimes (for example, PowerShell and TortoiseHG Workbench) which is really frustrating. For other apps (Chrome, Thunderbird) it works always.
Here is what I've found so far:
If you explicitly minimize a "problematic" app then you can never activate/maximize the window using the AHK shortcuts. I'm not sure if there are other scenarios that prevent the shortcuts from working but this is one certain way to replicate the problem (at least for me).
Even in the cases where the shortcuts don't work, I can see that the target app icon in the taskbar is getting highlighted. I guessing it works somewhat halfway, activating the window but not actually showing it.
I think the problem is not restricted to AutoHotKey only because I can replicate this behavior just with the Task Manager. If I go to the 'Applications' tab, right click on on target app and choose 'Bring to front', the same thing happens. BUT, if I choose 'Switch to' instead, it works!
So, I guess my question is what exactly does "Task Manager->Applications->Switch to" do and is there an equivalent that I can use in AHK. My OS is Win7.
Try to put a #WinActivateForce in your script.
If you run AutoHotkey as normal user, it may be unable to manage program running as administrator (for example PowerShell). If that's the case, try to run AutoHotkey as administrator.
If you explicitly minimize a "problematic" app then you can never
activate/maximize the window using the AHK shortcuts. I'm not sure if
there are other scenarios that prevent the shortcuts from working but
this is one certain way to replicate the problem (at least for me).
According to AutoHotkey's release notes, this is a known issue which was fixed in AutoHotkey v1.1.20. (Released 1 month after this question was asked)
1.1.20.00 - March 8, 2015
Changes
Changed WinActivate to restore the window if already active but minimized.
Changed WinActivate to look for a visible window to activate if DetectHiddenWindows is off and the active window is hidden, instead of
doing nothing

Open a new Firefox tab without focusing the browser window

I know that I can open a tab in Firefox from another program, for example using the following command:
firefox -new-tab https://stackoverflow.com/
When running this command, however, the Firefox window will get the focus (at least on Fedora 21 with Gnome 3). This is really annoying: My use case is that I browse through the headlines in my feed reader, which is a standalone program, and hit "open in browser" (which executes a configurable command, see above) on every article I'd like to read, before reading even one. This is necessary for example when I want to open tabs while I'm online but read them later while commuting or traveling.
Thus, my question boils down to the following:
Is there any way I can open a link in Firefox without needing to hit Alt+Tab every time to switch back from Firefox to the program I opened the tab with?

Do webdevelopers need "confim resend" protection?

I use firefox for my web development and I bet most of you guys too. I've been doing a lot of form development recently and this annoying message
"To display this page, Firefox must send information that will repeat any action (such as a search or order confirmation) that was performed earlier."
is just beginning to piss me off.. I mean, come on! I don't need protection on my localhost, thank you! So, my question is: are you aware of any config, hack, plugin to suppress it? If not, how do you live with it?
Apparently there is neither configuration option nor extension to turn off this annoying confirmation window.
However, the workaround I use is as follows.
Download and install application AutoHotkey from: http://www.autohotkey.com/
Create the following script:
^f5::
Send {f5}
sleep 100
Send {enter}
Save with .ahk extension.
Double click to run it (a new icon should show up in the system tray).
Now every time you press Ctrl+F5, the script presses F5 and then Enter. Voila, the confirmation window supressed.
Here's an equivalent of Patrick's answer for Linux users (Ubuntu in my case).
Install autokey (it's in the repos). Add this python script:
import time
keyboard.send_keys("<f5>")
time.sleep(0.5)
keyboard.send_keys("<enter>")
Hook this script to f5 and you will never see the confirm message again. Tested with latest firefox.

Resources