I'm trying to toggle to my new gmail message box but if it doesn't exist i would like my script to open gmail and open a new email (Compose new message).
Here's my existing script (previously provided by user285594)
^+m::
SetTitleMatchMode, 2
WinTitleC :="Compose Mail - "
IfWinExist, %WinTitleC%
{
WinActivate
return
}else{
SetTitleMatchMode, 2
IfWinExist, Chrome
WinActivate ;
WinWait, Chrome ;
sleep, 100 ;
chrome := "- Google Chrome"
found := "false"
tabSearch := "gmail"
curWinNum := 0
WinGet, numOfChrome, Count, %chrome% ; Get the number of chrome windows
WinActivateBottom, %chrome% ; Activate the least recent window
WinWaitActive %chrome% ; Wait until the window is active
ControlFocus, Chrome_RenderWidgetHostHWND1 ; Set the focus to tab control ???
while (curWinNum < numOfChrome and found = "false") {
WinGetTitle, firstTabTitle, A ; The initial tab title
title := firstTabTitle
Loop {
if(InStr(title, tabSearch)>0){
found := "true"
break
}
Send {Ctrl down}{Tab}{Ctrl up}
Sleep, 50
WinGetTitle, title, A ;get active window title
if(title = firstTabTitle){
break
}
}
WinActivateBottom, %chrome%
curWinNum := curWinNum + 1
}
ControlSend, , {Shift Down}c{Shift Up}, Google Chrome
winmove, Compose,, 1750, 303, 1725, 935 ; moving the window to my preferred position
if(found = "false"){
run C:\Program Files (x86)\Google\Chrome\Application\chrome.exe https://mail.google.com/mail/u/0/?ogbl#inbox
WinWait, Inbox
ControlSend, , {Shift Down}c , Google Chrome
winmove, Compose,, 1750, 303, 1725, 935; moving the window to my preferred position
}
}
return
It works when I have chrome open regardless of which tab I'm in. It does not work and seems to pause if chrome is minimized. What would you suggest?
I think the mistake lies on this line:
WinGetTitle, firstTabTitle, A ; The initial tab title
Here is a solution proposal:
#SingleInstance force
SetTitleMatchMode, 2
ComposeTitle = Compose Mail -
If WinExist(ComposeTitle . " ahk_exe chrome.exe") {
WinActivate
return
}
; Loop on all Chrome Windows
WinGet, id, List,ahk_exe Chrome.exe
found := False
tabSearch = Gmail
Loop, %id%
{
hWnd := id%A_Index%
WinActivate, ahk_id %hWnd%
; Loop on all Tabs in Chrome Window
WinGetTitle, firstTabTitle, A
title := firstTabTitle
Loop {
if (InStr(title, tabSearch)>0){
found = True
break
}
Send ^{Tab} ; switch to next tab
Sleep, 50
WinGetTitle, title, A ;get active window title
if (title = firstTabTitle){
break
}
} ; end Loop Tabs
if (found)
break
} ; end loop Chrome windows
If !(found) {
Run run C:\Program Files (x86)\Google\Chrome\Application\chrome.exe https://mail.google.com/mail/ca/u/0/#inbox"
WinWait, Inbox ahk_exe Chrome.exe
}
SendInput +c ; Shift+C
;WinWait %ComposeTitle%
;winmove, A,, 1750, 303, 1725, 935; moving the window to my preferred position
return
You can download the code from this gist.
Related
I have a Delphi app which prints HTML to PDF by opening the document in IE11 in the background and using the default PDF printer to print to PDF. This process works fine.
The issue is the following:
(Example I want to print 5 HTML documents to PDF.)
On the first run, it processes the first document fine, but then skips the rest with the following errors:
On Win Server 2016:
EOleSysErrorOLE A system shutdown has already been scheduled.
On Windows 10:
EOleSysErrorOLE error 8150002E
Then I wait until "iexplore.exe" closes, which takes a few sec.
From then, it processes all documents just fine regardless the number of the documents.
If I do not use the app for a long time (approx a day), it does the same as above.
It skips on the first run, then waits a few seconds and then us fine.
I tried to use OleVariant and IWebBrowser2, but both have the same outcome.
I close the Object with .Quit. (see in code below). I also tried Unassigned, Free, setting the Object to Null before creating a new object. None of them worked. Same outcome.
Here are a few thing which I tried as a workaround:
If I do not use .Quit, it works fine, but obviously won't close any iexplore.exe.
Also, if I open an IE window (GUI) and minimize it, the HTML-PDF process works fine.
I also tried to call to create a background IE object on TMainForm.FormCreate() when the app starts, and it works as well.
When it gets to the HTML-PDF process, it creates a new IE background object (additional "iexplore.exe") and closes it by leaving the one created on FormCreate().
I would like to figure out why it just cannot create and close an object fast enough on the first run (without having an IE opened or without using .Quit).
Here is the code:
Note: The program also writes some stuff to the registry, but I cut some lines for simplicity (I also might cut a few end here and there. Note that the function works fine apart than the issue above).
function THTMLMergeDocument.FilePrint: boolean;
var
BrowserObject: OleVariant;
ie : IWebBrowser2;
vaIn, vaOut: OleVariant;
OldHeader, OldFooter, OldPrinterName: String;
OldOrientation: Integer;
Registry : TRegistry;
ST, TOutVal: TDateTime;
sUrl : string;
Flag, TargetFrameName, PostData, Headers : OleVariant;
begin
result := false;
try
if fPrinterName = VTPrint.GetDefaultPrinter then
begin
try
//Tried OleVariant
{
BrowserObject := Unassigned;
BrowserObject := CreateOleObject('InternetExplorer.Application');
BrowserObject.Silent := true;
BrowserObject.Visible := false;
BrowserObject.Navigate('file:\\'+DocumentFileName);
BrowserObject.ExecWB(OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER);
while BrowserObject.Busy or BrowserObject.ReadyState <> READYSTATE_COMPLETE do
begin
Application.ProcessMessages;
end;
}
//Tried IWebBrowser2
ie := CoInternetExplorer.Create;
sUrl := 'file:\\'+DocumentFileName;
ie.Navigate(sUrl, Flag, TargetFrameName, PostData, Headers);
ie.ExecWB(OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER,vaIn,vaOut);
while ie.ReadyState <> READYSTATE_COMPLETE do
begin
Application.ProcessMessages;
end;
if (PDFOutput) then
begin
ST := Now;
TOutVal := EncodeTime(0,DocumentServerOptions.PDFConverterTimeOutInterval,0,0);
while not PDF.Completed and (Now-ST<TOutVal) do
Application.ProcessMessages;
if PDF.Completed then
result := true
else
WinWordLogProc('ERROR: No response received from PDF converter');
end
else
begin
result := true;
end;
ie.Quit; //close IWebBrowser2 object
BrowserObject.Quit; //close OleVariant object
except on E: Exception do
WinWordLogProc( 'Error class: ' + E.ClassName + #13 + E.Message);
end;
end
else
begin
WinWordLogProc('Error setting default printer to '+fPrinterName);
end;
finally
VTPrint.SetDefaultPrinter(OldPrinterName);
end;
`
I suspect that it has something do do with the IE object handling, but I'm not sure, hence asking for help here.
The browser's Navigate() method is asynchronous. You should wait for the document to finish loading before you then call ExecWB() to print the document, not after calling it.
chrome extensions
Error in the event handler: TypeError: Cannot set properties of null (setting 'value')
Hi all I wish to send text to a Textarea field by clicking a button or right-clicking on the page in Chrome but receive the above error.
I have this working on "other sites" where the Textarea is empty using chrome.tabs.sendMessage , and from looking up the process I understand what it means when the DOM has not loaded.
I can set the value by using the Chrome console and its works ok
document.getElementById("coverLetter").value('hello world')
here is some of my code
background.js =
var hello_World = 'hello_World'
function Shipped (info, tab) {
if (info.editable) {
chrome.tabs.sendMessage(tab.id, {
"text": hello_World
});
}
}
(This works as normal) but will not work on some pages,
I have two sites this will not work on upworks + people hour
what could be the problems here?
I am updating a cross platform app written in VS2010.
I need to provide driving instructions to the selected location.
I would like my app to open Google Maps (GM) in it’s own window with the best route already determined (as if the operator had opened GM themselves and selected the destination manually).
I have been following GM developer’s instructions but cannot get it to open GM on Android device, I can get it to open GM on iOS but it hangs (all have GM installed & on Wifi). I do not have a Google API key as instructions say it’s not needed.
iOS:
window.open("maps://www.google.com/maps/dir/?api=1&destination=-36.847456,174.830521&travelmode=driving");
Opens GM with last destination but sits on ‘Loading…’ forever
Android:
window.open("https://www.google.com/maps/dir/?api=1&origin=-36.852946,174.763348&destination=-36.847456,174.830521&travelmode=driving");
This opens a web page with recommended route selected, but with a ‘No internet’ banner. AndroidBanner
When I click [Navigate] I am asked if I want to use Google Maps app. When I click [Use the app] I get the application error below which takes me to a black screen so I must restart the app.
As an aside, pasting above url into chrome on Android returns ‘did not match any documents’.
net::ERR_UNKNOWN_URL_SCHEME(intent://maps.app.goo.gl/?link= https://www.google.com/maps/dir//-36.847456,174.830521/#-36.8660726,174.7966977,12z/data%3D!4m2!4m1!3e0!11m1!6b1&apn=com.google.android.apps.maps&amv=914018424&isi=585027354&ibi=com.google.Maps&ius=comgooglemapsurl&utm_campaign=ml_promo&ct=ml-navfab-nlu-o&mt=8&pt=9008#Intent;package=com.google.android.gms;scheme=https;S.browser_fallback_url=https://play.google.com/store/apps/details%3Fid%3Dcom.google.android.apps.maps&pcampaignid%3Dfdl_long&url%3Dhttps://www.google.com/maps/dir//-36.847456,174.830521/#-36.8660726,174.7966977,12z/data%253D!4m2!4m1!3e0!11m1!6b1&min_version%3D914018424;end;)
What am I missing?
Entire function that is called from a toolbar button complete with previous attempts:
mapsSelector: function () {
// helpful url: https://developers.google.com/maps/documentation/urls/ios-urlscheme
var mapURL = "https";
if /* if we're on iOS, open in Apple Maps */
((navigator.platform.indexOf("iPhone") != -1) ||
(navigator.platform.indexOf("iPad") != -1) ||
(navigator.platform.indexOf("iPod") != -1))
mapURL = "maps";
/*
mapURL = mapURL + "://www.google.com/maps/dir/" +
viewModel.Latitude_Now() + "," + viewModel.Longitude_Now() + "/" +
viewModel.Latitude_Destination() + "," + viewModel.Longitude_Destination() + ",17/" +
"am=t";
mapURL = "http://maps.google.com/maps?saddr=-36.91078,174.850896&daddr=-36.7492041,174.6866052";
mapURL = "https://www.google.com/maps/dir/?api=1&saddr=-36.91078,174.850896&daddr=-36.7492041,174.6866052";
mapURL = "https://www.google.com/maps/dir/?api=1&origin=-36.91078,174.850896&destination=-36.7492041,174.6866052&travelmode=driving";
*/
mapURL = "https://www.google.com/maps/dir/?api=1&origin=-36.852946,174.763348&destination=-36.847456,174.830521&travelmode=driving";
//mapURL = "maps://www.google.com/maps/dir/?api=1&destination=-36.847456,174.830521&travelmode=driving";
alert(mapURL);
window.open(mapURL);
}
I'm trying to do a shortcut with autohotkey (I am a noob with it) to go to chrome://settings/password/ when i'm on chrome.
The Run command works only for the URL, something like:
Run, http://stackoverflow.com
So I tried this script, but it's rough to me:
;myScript:
#IfWinActive, ahk_class Chrome_WidgetWin_1
^q::Send, ^t chrome://settings/passwords/ {enter}
#IfWinActive
There are some ways to do it better?
Try it step by step:
;myScript:
#IfWinActive, ahk_class Chrome_WidgetWin_1
^q::
Send, ^t
Sleep 500
; replace "title" with the exact title of the new window (tab)
; WinWait, title
; IfWinNotActive, title, ,WinActivate, title
; WinWaitActive, title
SendInput, chrome://settings/ ; SendInput is faster in sending text
Sleep 500
Send, {enter}
Sleep 500
; replace "title" with the exact title of the new window (tab)
; WinWait, title
; IfWinNotActive, title, ,WinActivate, title
; WinWaitActive, title
Send, {Tab 2}
Sleep 500
Send, {enter}
return
#IfWinActive
I usually incorporate a few loops to account for delays across old hardware, and just break out when the conditions are met.
You can trigger the Passwords box in Chrome with the below, currently bound to F4.
F4::
{
WinActivate, ahk_class Chrome_WidgetWin_1
Loop {
IfWinActive, ahk_class Chrome_WidgetWin_1
{
break
}
}
Send, ^t
Loop {
IfWinActive, New Tab - Google Chrome
{
break
}
}
Send, chrome://settings/passwords{enter}
}
return
I have a VBScript that uses InternetExplorer.Application to login to a website, then refresh the page every once in a while to keep the website from logging out due to inactivity. This sits on a dashboard screen mounted in our office. Is there a way to script Chrome in a similar way? It doesn't have to be VBScript, any language will do. We are looking to stop using Internet Explorer.
You can't control Google Chrome as an object in VBscript. Here's why: VBScript CreateObject Google Chrome
That being said, you CAN still manipulate a refresh on google chrome. Just copy the title of the page you want refreshing, and once the page has been activated, use a SendKeys command to cause it to refresh. e.g.(CTRL+R) - causes refresh, or in Sendkeys ("^r").
Once you've got it refreshing, just set it in a loop and set your wait period for however long you want.
'This is an infinite loop, only disposed of by exiting Wscript.exe or Cscript.exe
Do While(true)
Dim PageTitleToRefresh, IntervalinSeconds, x, objShell, Success
'Page Titles - NOT the page address - (google.com = NO) (Google = YES)
'Page Titles are normally stored at the top of the browser or in the tab name of the browser.
PageTitleToRefresh = "Google"
IntervalinSeconds = 10
x = IntervalinSeconds * 1000
Set objShell = WScript.CreateObject("WScript.Shell")
Do Until Success = True
Success = objShell.AppActivate(PageTitleToRefresh)
Wscript.Sleep 1000
Loop
wscript.echo "Activated, now refreshing"
objShell.SendKeys "^r"
Wscript.Sleep IntervalinSeconds
Loop
here is a way that I edited in js file, but can be also realized in vbs :
var fso = new ActiveXObject("Scripting.FileSystemObject");
var chrome = "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe";
var url = 'http://google.com';
if (fso.FileExists(chrome)){
var objShell = WScript.CreateObject("Shell.Application");
objShell.ShellExecute(chrome, "--app="+url, "", "", 1);
}
else{ //if chrome doesn''t exists, so launch ie :
oIE1 = WScript.CreateObject ("InternetExplorer.Application");
oIE1.Visible = 1;
oIE1.AddressBar = 0;
oIE1.StatusBar = 0;
oIE1.ToolBar = 0;
oIE1.MenuBar = 0;
oIE1.Navigate(url);
}