Jump to content

Web Search Workflow can't handle spaces

Recommended Posts

Hi, everyone.


Am new in the community and i don't know anything about code.

But i did this workflow, a web search in google that open in another window, everything works fine but when i search something more then 1 word it bugs and doesn't do anything.

This is the code, i will appreciate very much any help.


Thank You.

Captura de Pantalla 2021-11-05 a la(s) 3.39.39 a.m..png

Link to comment
15 hours ago, Imjustr2d2 said:

it bugs and doesn't do anything.


There are a whole bunch of characters that aren't allowed in URLs, including spaces. They need to be converted to a URL-friendly format (e.g. by replacing spaces with + signs), and you can't do that (easily) in AppleScript.


Put this script in a Run Script box with Language = "/usr/bin/osascript (JavaScript)" and "with input as argv":


function run(argv) {
	// query is first command-line argument
	let query = argv[0] + ' meaning'
	// escape spaces and other characters not allowed in URLs
	let url = 'https://www.google.mx/search?q=' + encodeURIComponent(query)
	// open a new browser window with search URL
	const edge = Application('Microsoft Edge')
	edge.activate() // bring Edge to the front
	let win = edge.Window().make()
	win.tabs[0].url = url


Note: I don’t have Microsoft Edge to test this with, but it works in Chrome. You could probably also use the --new-window http://... command-line flag to the Edge binary, but you’d still need to properly encode the URL.

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Create New...