开发者

Scheduled task to open URL

开发者 https://www.devze.com 2022-12-26 23:10 出处:网络
At a certain time each day, I\'d like my browser to pop open a tab to a certain URL. 开发者_如何学Python

At a certain time each day, I'd like my browser to pop open a tab to a certain URL.

开发者_如何学Python

My goals:

  1. be able to set the URL from the scheduled task
  2. use the default browser (rather than hard-coding it)

I can't seem to accomplish both of these goals at once. I'll post my partial solutions as answers, but I'm hoping someone will have something better.


Note that this command will open the default browser (or a new tab therein) to the given url:

cmd /c start http://example.com

To create a scheduled task without the command window popping up:

Create OpenUrl.vbs:

CreateObject("Wscript.Shell").Run "cmd /c start " & Wscript.Arguments.Item(0), 0, False

Then call it from a scheduled task with this command:

wscript.exe "C:\Path\To\Script\OpenUrl.vbs" http://example.com


This solution is hard-coded to Firefox:

Create the scheduled task with this URL:

"C:\Program Files\Mozilla Firefox\firefox.exe" -new-tab http://example.com


Well, you could just create the url file from your script :

Dim fso, MyFile
Set fso = CreateObject("Scripting.FileSystemObject")
Set MyFile= fso.CreateTextFile("c:\example.url", True)
MyFile.WriteLine("[InternetShortcut]")
MyFile.WriteLine("URL=http://stackoverflow.com/questions/2655253/scheduled-task-to-open-url")
MyFile.Close


This solution doesn't allow me to set the URL from the scheduled task:

Create a .url file pointing to the URL I want.

Create a .vbs script that opens the URL:

CreateObject("Wscript.Shell").Run """example.url""", 0, False

Create the scheduled task to run the .vbs script.


One additional thing to note for the FF solution - if your URL has ampersands in it - you may need to escape those in Scheduled tasks using the caret ^& character.

Oops - this is wrong. The ^ was needed to escape the Ampersand when testing the link in a CMD window - but is okay in the actual Scheduled Task.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号