Wednesday, October 27, 2021

[SOLVED] How can I open a firefox tab with a shell script and close the tab after a few seconds?

Issue

This is what I have so far:

Start-Process -FilePath Firefox -ArgumentList www.google.com
start-Sleep -Seconds 40

killall Firefox

start-Sleep -Seconds 5

Start-Process -FilePath Firefox -ArgumentList www.youtube.com

...

Basically I want the shell script to open a firefox tab of google.com, spend 40 seconds on that website, then close the tab and wait 5 seconds before opening up youtube.com.

I don't have any shell script experience, but wrote the following pseudocode. Any feedback on what the proper syntax/method would be would be helpful!


Solution

this should do the job:

Start-Process -FilePath Firefox -ArgumentList www.google.com
start-Sleep -Seconds 40

Get-Process firefox | Stop-Process

start-Sleep -Seconds 5

Start-Process -FilePath Firefox -ArgumentList www.youtube.com

Note:

by default firefox has activated the session restore so when firefox starts after a crash (or after the stop-process) the restore tab will also be opened. To avoid it you must disable it:

Open about:config in the Firefox location bar Type browser.sessionstore.resume_from_crash in the filter box, or search for it manually Double click

browser.sessionstore.resume_from_crash

It should change from

browser.sessionstore.resume_from_crash default boolean true

to

browser.sessionstore.resume_from_crash user_set boolean false

Close and restart Firefox



Answered By - Danfossi