I am trying to use AutoHotkey (v1.1.15.02) to automatically use one of my search engines in Firefox (31.0).
I thought the best way to call the search engine is to use my predefined key words. Usually, if I type "d awesome", Firefox will open "http://dictionary.reference.com/browse/awesome" for me.
Now I just want to get the same behaviour when I call Firefox from AutoHotkey. I thought it should work with this code:
#ä::
send ^c
IfWinExist, ahk_class MozillaWindowClass
{ WinActivate
Send ^t{Space}
SetKeyDelay 100,100
sleep 500
Send d ^v{Enter}
}
else
{
Run firefox
sleep 2500
Send {F6}d ^v{Enter}
}
return
It does almost everything it should, except firefox keeps using google to search "d awesome" instead of calling my predefined search engine. Any ideas on how Firefox can recognize the key?
In the end I realized what I was trying to do is a lot faster if I just call the search directly as an URL in firefox. I'm posting my solution in the hope that other autohotkey users may find it beneficial:
#^e::
send ^c
Clipwait
sleep 200
Run C:\Program Files (x86)\Mozilla Firefox\firefox.exe "http://dictionary.reference.com/browse/%ClipBoard%"
return
It is important for performance to call firefox with the full path!
Related
I'm trying to switch between virtual desktops on win10 using the XButton1 and XButton2 of my mouse.
So far this is working quite alright, except the fact that when I have for example Firefox as my active scope, obviously those buttons are used to go forward/backward (problem appears in every window using these buttons for something).
This seems to prevent AHK from either noticing that I used the configured trigger or not executing the script (which I believe is less likely).
For Firefox I found a workaround by disabling the use of these buttons in the [about: config](about config) page by setting mousbutton.4th.enable and mouse button.5th.enable to false but this won't work for everything since there isn't always a way to disable these buttons.
I have tried to use the mouse-wheel tilting buttons as well but the default usage oh them is even more common in the programs I'm working with.
Here is the script I am using.
# NoEnv; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
XButton1::Send ^#{Left}
XButton2::Send ^#{Right}
return
If someone has a workaround or a completely different idea (for example a totally obvious Win10 feature/setting I'm missing) I would be absolutely happy.
You can define custom combinations for those two keys in your script
e.g.
XButton1 & LButton::return ; do nothing
; or another action:
; XButton1 & LButton:: Run notepad
XButton1::Send ^#{Left}
XButton2 & a::return
XButton2::Send ^#{Right}
This way the keys lose their native function in the programs.
For details, see Custom Combinations.
EDIT:
If a program is running with admin privileges, then AHK won't intercept the key presses, and that could very well be the reason behind this problem.
If that is the case, try to run the AHK script as administrator by adding this to the auto-execute section (top of the script):
; If the script is not elevated, relaunch as administrator and kill current instance:
full_command_line := DllCall("GetCommandLine", "str")
if not (A_IsAdmin or RegExMatch(full_command_line, " /restart(?!\S)"))
{
try ; leads to having the script re-launching itself as administrator
{
if A_IsCompiled
Run *RunAs "%A_ScriptFullPath%" /restart
else
Run *RunAs "%A_AhkPath%" /restart "%A_ScriptFullPath%"
}
ExitApp
}
https://autohotkey.com/docs/commands/Run.htm#RunAs.
When in need to use AHK the solution from user3419297 works perfekt.
Another way to accomplish the same result is to use X-Mouse Button Control.
Simply set Mouse Button 4/5 to Simulated Keys: with {CTRL}{LWIN}{RIGHT} and {CTRL}{LWIN}{LEFT}.
I would like to make message pop-up in Autohotkey when there is new message in Outlook. I have tried to use ComObjActive("Outlook.Application") with no joy. Also documentation for COM objects is pretty vague on Autohotkey site. Message should be like msgbox New Mail Received. This is similar to default message pop-up in Outlook. I just need this in AHK.
Main reason is that I'm using Desktops from Sysinternals. This program makes 4 separated desktops. When I run outlook on one desktop, I can't see new message pop-up from outlook on the other desktop. I need a simple AHK script that will tell me when there is a new mail, when I'm on different desktop than the one that is running Outlook.
In the System-StatusBar, their is an icon of outlook, which changes\animates for sometime when a new mail is received.
We can use AutoHotKey > ImageSearch/PixelSearch for the same to find the difference.
Add a SetTimer with ImageSearch/PixelSearch.
Compare and If difference is found >> You Got A Mail.
As Simple As That. If you need futher help with Scripting, Please feel free :)
Hope this Helps :)
I'm not used to AHK but after some research I came up with the following AHK script which should do what you need:
oOutlook = ComObjActive("Outlook.Application")
ComObjConnect(oOutlook, "outlook_")
return
outlook_NewMail() ;uses the COM event NewMail
{
msgbox New Mail Received
oOutlook.Visible := 1 ;make Outlook visible
oOutlook.Activate ;and bring to front
}
To stop listening to the outlook COM events use
ComObjConnect(oOutlook)
Currently I am writing a script that invokes a new instance of the chrome browser.
I know how to call chrome to open a *.html document in a new tab.
google-chrome *.html
Chrome will open a new tab to show that file.
How can I close the tab in terminal without closing other tabs or closing the browser window?
only linux answer:
Perhaps wmctrl could be of some assistance. You could use the -c option that closes a window gracefully:
wmctrl -c "tab title"
The string chrome is matched against the window titles. Note that the window might not close if some message pops-up (e.g. when you have multiple tabs open).
You can look into chrome remote debugging:
chromium --remote-debugging-port=9222
and connect to it with some kind of client ( https://github.com/cyrus-and/chrome-remote-interface seems good). The debug protocol is used for a number of applications, but with some work you can achieve the kind of functionality you want. Here are some docs for you to check out: https://chromedevtools.github.io/devtools-protocol/tot/Page
Or perhaps chromix-too, which is based on an extension, daemon and client architecture.
https://github.com/smblott-github/chromix-too
This seems to be much easier to use, and might be exactly what you want, though the extension is a bit inconvenient, and there seems to be demand for more capabilities to be supported.
EDIT The query you would be looking for is:
const chrome = require('ox-chrome-remote-interface');
chrome.List().then(tabs=>{
const list = tabs
.filter(t=>t.type == 'page' && t.title.includes(TITLE))
.map(t => t.id)
if(list.length==1){
chrome.Close({id:list[0]})
} else {
console.error(`${list.length} tabs match.`)
}
})
Solved! See [SOLUTION]
Thanks for any help you can provide. It's much appreciated!
In a nutshell: I'm trying to send Ctrl+V to SSMS 2012 with SendKeys.Send("^{v}"), but it doesn't work. It's working fine with Notepad, UltraEdit, Word, Excel, Chrome, you name it. It even works in Microsoft Visual Studio 2010.
In details: I have an application that runs in the background. Using a keyboard shortcut, this application displays a popup window with options. Depending on the option I choose it saves what's related to it into the clipboard. I then close that popup window, get the new foreground window (which should be the one I had before displaying the popup) and try to paste what's in my clipboard with SendKeys.
It works with pretty much every application I try it with, except SSMS
If I manually press Ctrl+V it pastes what I have in my clipboard (text usually)
I've added some code to display the title of the window I got with the GetForegroundWindow and it does give me the correct SSMS window
What's sad about all this is that once in a while (very rarely), the text is correctly pasted in SSMS, but it doesn't work the second after.
I never get the MessageBox saying the SetForegroundWindow failed.
If I replace the single SendKey with 3 SendKeys to send "A", "B" and "C", B and C are sent but not A. Yes I've tried using a sleep thinking it needed time to write the first SendKey, but that didn't change anything.
I did try SendKeys.SendWait instead, but didn't get different results.
Here's the code from the moment I close the popup
this.Close();
IntPtr handle = GetForegroundWindow();
if (!handle.Equals(IntPtr.Zero))
{
if (SetForegroundWindow(handle))
{
//Optionnal just to show the window title
const int nChars = 256;
StringBuilder Buff = new StringBuilder(nChars);
if (GetWindowText(handle, Buff, nChars) > 0)
{
MessageBox.Show(Buff.ToString());
}
//[SOLUTION] Sending a useless key seems to solve my SSMS problem without affecting the other applications.
SendKeys.Send("{F14}");
//Sending Ctrl+V
SendKeys.Send("^{v}");
}
else
{
MessageBox.Show("SetForegroundWindow failed");
}
}
Hope someone can help.
Thanks in advance!
See http://msdn.microsoft.com/en-us/library/system.windows.forms.sendkeys.aspx
...
The SendKeys class is susceptible to timing issues, which some developers have had to work around. The updated implementation is still susceptible to timing issues, but is slightly faster and may require changes to the workarounds. The SendKeys class tries to use the previous implementation first, and if that fails, uses the new implementation. As a result, the SendKeys class may behave differently on different operating systems. Additionally, when the SendKeys class uses the new implementation, the SendWait method will not wait for messages to be processed when they are sent to another process.
...
I'm using Selenium Client 2.4.0 on Mac 10.6.6 with Firefox 5. Using the WebBackedSeleniumDriver, I'm running a "selenium.getEval" command that causes a Firefox warning,
"Warning: Unresponsive script.
A script on this page may be busy, or it may have stopped responding. You can stop the script now, or you can continue to see if the script will complete.
Script: resource://fxdriver/modules/utils.js:9161"
The value of "dom.max_script_run_time" about:config was "0", which should disable the above dialog altogether. Yet, I still get the dialog. Is there any way to prevent the warning dialog from appearing?
dom.max_script_run_time is the right preference but it only applies to web pages. Browser UI (and extensions like fxdriver are part of it) are restricted by the preference dom.max_chrome_script_run_time however (default value is 20 seconds). You should set it to 0 as well.
Documentation: https://developer.mozilla.org/en/Preferences/Mozilla_preferences_for_uber-geeks#DOM_preferences
Regardless of what you have setup in your profile, during startup, Selenium sets both values to 2417483647 to try and get around the browser warning. However, because the value is so large, FF ends up ignoring it and using the default value of 10/20 instead. This is true even if you're pointing Selenium to use your profile as the template.
The best way I've found to get around this is to specify
-timeout nnnn
to the Selenium Server startup args. This sets both the server and client (browser) timeout values.
Although this thread is quite old, the problem still exists with current selenium and firefox builds. I've got these really annoying messages quite a long time now, without a good fix. Asking the devolopers / mailing list / google usually results in the following answer:
The javascript used in your application is too fat or buggy, improving your scripts will help.
As this is no option in a larger company, when you depend on a framework you have no access to, i decided to search for the root cause for myself.
The core of the problem is the fact, that selenium overrides profile settings if you specify the -timeout nnnn parameter. So creating a custom firefox profile template and setting the dom.max_script_run_time and dom.max_chrome_script_run_time will not work here.
As soon as you specify the -timeout parameter, these two settings are overriden with the value you provide to the parameter. After hours of debugging and testing i noticed some facts:
If you don't specify -timeout, firefox runs for exact 30 minutes, without one script timeout. After that, firefox gets killed by selenium with a SeleniumCommandTimedOutException
As soon as you specify -timeout (no matter which value), the script timeout appears after several seconds or minutes. These messages are independent to the timeout-value.
The -browserTimeout parameter isn't usefull as i haven't found where this parameter is used in the source.
As we have some testsuites that run longer than 30 minutes we have 2 options to fix this behaviour:
Rewriting our testsuites and splitting them to run within the 30 minutes window
Patching selenium to run longer than 30 minutes
Do not use the -timeout parameter.
So choose for yourself which option is better. I created a small and simple patch for the HTMLLauncher.java to allow 90 minutes instead of the default 30.
diff --git a/java/server/src/org/openqa/selenium/server/htmlrunner/HTMLLauncher.java b/java/server/src/org/openqa/selenium/server/htmlrunner/HTMLLauncher.java
index c2296a5..310b39f 100644
--- a/java/server/src/org/openqa/selenium/server/htmlrunner/HTMLLauncher.java
+++ b/java/server/src/org/openqa/selenium/server/htmlrunner/HTMLLauncher.java
## -146,6 +146,16 ##
launcher.launchHTMLSuite(suiteURL, browserURL);
sleepTight(timeoutInMs);
+ // SFR, Patch 2013-10-17: To get rid of the damn SeleniumCommandTimedOutException
+ // we allow the Suite to run 3 times as long as per default (30 min -> 90 min).
+ if(results == null) {
+ log.warning("SFR, Patch 2013-10-17");
+ sleepTight(timeoutInMs);
+ }
+ if(results == null) {
+ log.warning("SFR, Patch 2013-10-17");
+ sleepTight(timeoutInMs);
+ }
launcher.close();
I'll upload a pre-compiled jar with the above patch if necessary.
Go the hidden configuration page in Firefox by typing about:config in the address bar . (make sure that you are doing this for the profile you are using for selenium) In the 'Filter' box, type script_run_time.
This will narrow the options to dom.max_script_run_time and dom.max_chrome_script_run_time. Right-click it and choose Modify. A box pops up. Change the number to something bigger like 40. This is the maximum time a script can run before Firefox considers it 'unresponsive'. If you can’t find the string in the about:config page, create it by right-clicking anywhere and then choose New—> Integer and enter there name and values (when asked)
Set it to a very large number instead of "20"?
The dom.max_script_run_time setting is in seconds. Changing it from 10 to 20 just doubles the amount of time to wait. A value of 0 will disable it, but this could result in a run-away script locking up your browser. You might just use a really large value.
More details here:
http://kb.mozillazine.org/Dom.max_script_run_time
This issue appears for me when I do Selenium calls while web application is running some own crappy slow JS. Even if I catch the popup and retry after few seconds, FF is not responsive to Selenium anymore. The solution is to just put sleep 10 before otherwise any Selenium call would result in popup.