Shell script for searching custom search engine no longer works in Catalina (Ruby)

I recently upgraded from Mac OS Mojave to Catalina. On Mojave, I used a quick action to perform web searches via Google's encrypted search engine at encrypted.google.com. The quick action script is open "https://encrypted.google.com/search?q=$(ruby -rcgi -e 'print CGI.escape $<.read.chomp')".

This script no longer works in Catalina due to deprecated Ruby support. Does anyone know how I could script the same action in Catalina?


Since you have both the applescript and automator tags on your question, here is another approach using a Run AppleScript action in Automator...

I'd use 'Listing 32-7 AppleScriptObjC: Handler that URL encodes text' from Encoding and Decoding Text.

Example AppleScript code:

use framework "Foundation"
use scripting additions

on run {input, parameters}
    open location "https://encrypted.google.com/search?q=" & encodeText(input as string)
end run

on encodeText(theText)
    set theString to stringWithString_(theText) of NSString of current application
    set theEncoding to NSUTF8StringEncoding of current application
    set theAdjustedString to stringByAddingPercentEscapesUsingEncoding_(theEncoding) of theString
    return (theAdjustedString as string)
end encodeText