StrokesPlus.net Forum
»
General Discussion
»
Scripts
»
Duplicate/Clone firefox tab to new window
Rank: Member
Groups: Approved
Joined: 8/11/2019(UTC) Posts: 16 Thanks: 3 times
|
Dear Rob, thank you very much for your great tool. And sorry to all scripting pros. As a total noob my script(s) fail at some point. The goal is to copy a tab in firefox, move the new window to the left screen and position the mouse on the new screen: sp.SendKeys("^l"); sp.SendKeys("+{Enter}"); var scr = action.Window.MoveToPreviousScreen(); sp.ConsumePhysicalInput(true); sp.MouseMove(new Point(scr.Bounds.Left + (scr.Bounds.Width / 2), scr.Bounds.Top + (scr.Bounds.Height / 2))); sp.ConsumePhysicalInput(false); The old window is moved to the new screen, the new window stays, not maximized. All other approaches failed as well. E.g.: sp.SendKeys("^l"); sp.Sleep(8); sp.SendKeys("+{Enter}"); sp.Sleep(8); sp.SendModifiedVKeys([vk.LWIN], [vk.LEFT]); sp.Sleep(8); sp.SendModifiedVKeys([vk.LWIN], [vk.LEFT]); sp.SendKeys("% "); sp.Sleep(8); sp.SendKeys("x"); or sp.SendKeys("^l"); sp.Sleep(5); sp.SendKeys("+{Enter}"); sp.Sleep(5); sp.SendAltDown(); sp.SendKeys("{Tab}"); sp.Sleep(5); sp.SendKeys("{Left}"); sp.Sleep(5); sp.SendKeys("{Enter}"); sp.SendAltUp(); sp.Sleep(5); sp.SendModifiedVKeys([vk.LWIN], [vk.LEFT]); sp.Sleep(5); sp.SendModifiedVKeys([vk.LWIN], [vk.LEFT]); sp.Sleep(5); sp.SendKeys("% "); sp.Sleep(5); sp.SendKeys("x"); How can I activate the new window (typing the shortcuts directly works) in order to move and maximize it? Thanks for any suggestions. Alex Edited by user Tuesday, August 13, 2019 5:05:43 PM(UTC)
| Reason: Subject more specific
|
|
|
|
Rank: Advanced Member
Groups: Approved
Joined: 9/13/2018(UTC) Posts: 54 Thanks: 18 times Was thanked: 18 time(s) in 13 post(s)
|
Hi I almost made the code, I just need a little correction.
|
1 user thanked Yuichi for this useful post.
|
|
|
Rank: Advanced Member
Groups: Approved
Joined: 9/13/2018(UTC) Posts: 54 Thanks: 18 times Was thanked: 18 time(s) in 13 post(s)
|
Hi I hope if this will works because i don't have way to test it Try it and tell me.Code:if (sp.ForegroundWindow().ClassName == "MozillaWindowClass") {
var clipboard = clip.GetText(); // save text from clipboard
if (!clipboard) clipboard = " ";
sp.SendModifiedVKeys([vk.LCONTROL], [vk.VK_L]); // focus on adress bar
sp.Sleep(30);
sp.SendModifiedVKeys([vk.LCONTROL], [vk.VK_C]); // copy url
sp.Sleep(30);
var url = clip.GetText(); // get url
clip.SetText(clipboard); // restore clip
var wHWnd = sp.ForegroundWindow().HWnd;
// command "-foreground" will set new window as active
sp.RunProgram("C:\\Program Files\\Mozilla Firefox\\firefox.exe", "-new-window " + '"' + url + '"' + " -foreground", "", "", true, false, false); // run as new window
// wait for new window
while (sp.ForegroundWindow().HWnd == wHWnd) {
sp.Sleep(50);
}
sp.Sleep(150);
var wnd = sp.ForegroundWindow(); // get active window
wnd.MoveToPreviousScreen(); // move window
//wnd.Maximize(); // uncomment to maximize new window
// move cursor
var scrWidth = Screen.FromHandle(wnd.HWnd).Bounds.Width; // get the screen size in which the new window is located
var scrHeight = Screen.FromHandle(wnd.HWnd).Bounds.Height;
sp.MouseMove(new Point(Math.floor(scrWidth / 2), Math.floor(scrHeight/ 3)));
}
|
2 users thanked Yuichi for this useful post.
|
Alex on 8/14/2019(UTC), Rob on 8/14/2019(UTC)
|
|
Rank: Member
Groups: Approved
Joined: 8/11/2019(UTC) Posts: 16 Thanks: 3 times
|
Hi Yuichi, thank you for your efforts. Your script is working like a charm. I only had to adapt the application path AND increase the waiting time (outside your while statement!) from 150 to 200ms (already worked at 180) for the new window to come up. Thank you! Alex Edited by user Wednesday, August 14, 2019 5:37:37 PM(UTC)
| Reason: Not specified
|
|
|
|
Rank: Advanced Member
Groups: Approved
Joined: 9/13/2018(UTC) Posts: 54 Thanks: 18 times Was thanked: 18 time(s) in 13 post(s)
|
A slightly updated version, for a clear conscience.
Code:if (sp.ForegroundWindow().ClassName == "MozillaWindowClass") {
// GET URL
var clipboard = clip.GetText(); // save text from clipboard
if (!clipboard) clipboard = " ";
sp.SendModifiedVKeys([vk.LCONTROL], [vk.VK_L]); // focus on adress bar
sp.Sleep(30);
sp.SendModifiedVKeys([vk.LCONTROL], [vk.VK_C]); // copy url
sp.Sleep(30);
var url = clip.GetText(); // get url
clip.SetText(clipboard); // restore clip
if (url.includes("://")) { // is a url?
// RUN NEW WINDOW
sp.RunProgram(sp.ExpandEnvironmentVariables("%PROGRAMW6432%") + "\\Mozilla Firefox\\firefox.exe", "-foreground -new-window " + '"' + url + '"' , "", "", true, false, false);
sp.Sleep(300);
// MOVE NEW WINDOW TO FIRST SCREEN
var wnd = sp.ForegroundWindow(); // get active window
wnd.MoveToScreen(0); // move window
var scrWidth = Screen.FromHandle(wnd.HWnd).Bounds.Width; // get the screen size in which the new window is located
var scrHeight = Screen.FromHandle(wnd.HWnd).Bounds.Height;
sp.MouseMove(new Point(Math.floor(scrWidth/2), Math.floor(scrHeight/3)));
//wnd.Maximize(); // uncomment to maximize new window
}
}
|
|
|
|
Rank: Member
Groups: Approved
Joined: 8/11/2019(UTC) Posts: 16 Thanks: 3 times
|
Great! Since my 64bit firefox version resides in its old 32bit path I added/changed some lines: Code:if (sp.ForegroundWindow().ClassName == "MozillaWindowClass") {
// SAVE CLIP
if(clip.ContainsAudio()) { var savedclip = clip.GetAudioStream(); sp.StoreNumber("clipcase", 1); } // save clip
else if (clip.ContainsFileDropList()) { var savedclip = clip.GetFileDropList(); sp.StoreNumber("clipcase", 2); }
else if (clip.ContainsImage()) { var savedclip = clip.GetImage(); sp.StoreNumber("clipcase", 3); }
else if (clip.ContainsText()) { var savedclip = clip.GetText(); sp.StoreNumber("clipcase", 4); }
if (!savedclip) savedclip = " ";
// GET URL
sp.SendModifiedVKeys([vk.LCONTROL], [vk.VK_L]); // focus on address bar
sp.Sleep(30);
sp.SendModifiedVKeys([vk.LCONTROL], [vk.VK_C]); // copy url
sp.Sleep(30);
var url = clip.GetText(); // get url
switch (sp.GetStoredNumber("clipcase")) { // restore clip
case 1: clip.SetAudio(savedclip); break;
case 2: clip.SetFileDropList(savedclip); break;
case 3: clip.SetImage(savedclip); break;
case 4: clip.SetText(savedclip); break;
}
sp.DeleteStoredNumber("clipcase");
if (url.includes("://")) { // is a url?
// RUN NEW WINDOW
var ffpath = "\\Mozilla Firefox\\firefox.exe";
var env = sp.ExpandEnvironmentVariables("%ProgramFiles%") + ffpath;
var env32 = sp.ExpandEnvironmentVariables("%ProgramFiles(X86)%") + ffpath;
var env64 = sp.ExpandEnvironmentVariables("%ProgramW6432%") + ffpath;
if (File.Exists(env)) var apppath = env;
if (File.Exists(env32)) var apppath = env32;
if (File.Exists(env64)) var apppath = env64;
sp.RunProgram(apppath, "-foreground -new-window " + '"' + url + '"' , "", "", true, false, false);
sp.Sleep(300);
// MOVE NEW WINDOW TO PREVIOUS SCREEN <- Change "...PreviousScreen()" to "...NextScreen()" for next screen as destination
var wnd = sp.ForegroundWindow(); // get active window
wnd.MoveToPreviousScreen(); // move window
var scrWidth = Screen.FromHandle(wnd.HWnd).Bounds.Width; // get the screen size in which the new window is located
var scrHeight = Screen.FromHandle(wnd.HWnd).Bounds.Height;
sp.ConsumePhysicalInput(true);
sp.MouseMove(new Point(Math.floor(scrWidth/2), Math.floor(scrHeight/2)));
sp.ConsumePhysicalInput(false);
//wnd.Maximize(); // uncomment to maximize new window
}
}
Edited by user Saturday, August 17, 2019 8:28:17 AM(UTC)
| Reason: Not specified
|
|
|
|
StrokesPlus.net Forum
»
General Discussion
»
Scripts
»
Duplicate/Clone firefox tab to new window
Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.
Important Information:
The StrokesPlus.net Forum uses cookies. By continuing to browse this site, you are agreeing to our use of cookies.
More Details
Close