Sumatra PDF is a PDF, ePub, MOBI, CHM, XPS, DjVu, CBZ, CBR reader for Windows

[Advanced Tips] Pass selection to another app e.g. Web Search

There have been many requests to be able to pass the selected text to a translation or web lookup / search like this

Most work around suggestions are to use a 3rd party macro tool such as AutoHotKey. However, there is a Windows Scripting tool built into most versions. So here is a configurable method using that tool.

' Script template to paste selected word(s) in browser
' Expects a word or more has been selected e.g. double click will select that word
' Save this file as WebSearch.vbs in a known path
' Usage:- Add to SumatraPdf-settings.txt replacing existing entry
' ExternalViewers [
'	[
'		CommandLine = "C:\Windows\System32\wscript.exe" "C:\known path\WebSearch.vbs"
'		Name = &Browser Search
'		Filter = *.*
'	]
' ]
' select some text e.g. double click a word then use shortcut ALT+F+B or file menu item "Open in Browser Search"
Set WshShell = WScript.CreateObject("WScript.Shell")
' Copy selected text to clipboard
WshShell.Sendkeys "^c"

'Fetch Text from clipboard and prep for search
Set objClipboard = CreateObject("htmlfile")
SearchString = objClipboard.ParentWindow.ClipboardData.GetData("Text")

' remove the ' from start of only one of "MyBrowser" setting below or replace with your own
'MyBrowser="C:\Program Files (x86)\Microsoft\Edge Beta\Application\msedge.exe"
MyBrowser="C:\Program Files\Internet Explorer\iexplore.exe"

' remove the ' from start of only one of "MySearch" setting below or replace with your own

'The following are for a Dictionary look-up (use with single words)
' The following are examples for translate English to français (use website address bar to see codes for other languages

' ensure value is not too low otherwise commands may fail
WScript.Sleep 10
WshShell.Run "c:\windows\System32\cmd.exe /c "+""""+""""+MyBrowser+""""+" "+""""+MySearch+SearchString+""""+"""", 2

Ensure you select everything in the code window and save to a filename such as WebSearch.vbs beware the extension must be .vbs NOT .vbs.txt
Note the correct path to that .vbs file and use the guide at start of file as to how to add the CommandLine into Settings > Advanced Options especially the need to replace “known path” with the folder location you used.

This could be a good addition to Sumatra docs.

@GitHubRulesOK (and anyone else who’s interested in improving Sumatra documentation): I just moved majority of Sumatra docs to Notion and build a system to automate publishing the docs to the website. That makes it easy to add more content / edit existing content.

In other words: the source to is

Currently anyone can leave comments in Notion.

If you sign up to (they have a free tier) and send me the e-mail you use for that, I can add you as an editor so that you can make direct changes, add more content.

I’ll periodically push those changes to the website.