Skip to content

Another way to open stock charts from mop in Terminal

On Sunday, I posted about my geeky solution to my non-functional Stocks Dashboard widget in Mojave. Then earlier today, I crafted a way to view one of the tracked stock's charts with a mouse click.

A commenter asked if there were any way to view the charts using a built-in tool, as purchasing Keyboard Maestro for just this one task is expensive (and a waste of Keyboard Maestro's capabilities). And in reality, when I first started working on my solution, I started in Automator…but quickly grew frustrated by its inability to do even basic text manipulation.

But then today, I remembered I can use AppleScript in Automator to work with the text, and the solution came together quickly after that: A new Service that appears when you right-click on text in a Terminal window:

To use this, download the action, unzip it, and then double-click the unzipped file. You should be prompted to install the workflow:

And if you want to use e-Trade to display your charts, that's all you'll need to do. If you'd rather use another service, though, you'll have to edit the action. Open Automator, find the action in your user's Library > Services folder, and then drag it onto Automator's Dock icon.

The workflow should open, and it will look like this:

You'll need to edit the AppleScript line that begins set theURL to. Start by visiting your charting site in a browser, and loading any stock's chart. Now copy the URL, and put it in TextEdit or some other text editor. Here's an example of a URL from barchart.com:

https://www.barchart.com/stocks/quotes/AAPL/overview

You need to convert this into a combination of string and variables that AppleScript will recognize—any reference to the ticker symbol needs to be replaced with (input as text), but that cannot appear with "normal" text, so you need to structure it like this:

"https://www.barchart.com/stocks/quotes/" & (input as text) & "/overview"

Once you've edited the URL as above, copy it, and then paste it into the workflow, replacing everything after "set the URL to " (leave the trailing space). The final line would look like this:

set theURL to "https://www.barchart.com/stocks/quotes/" & (input as text) & "/overview"

Save the script, and now you should see charts from the site you put into the workflow.

This is a bit more time consuming to use than the Keyboard Maestro version, but it works well, and doesn't rely on any non-bundled apps.

4 thoughts on “Another way to open stock charts from mop in Terminal”

  1. Enjoyed working with setting up mop & getting the Open Stock Chart to open in the MacOS Terminal.
    Just trying to figure out how to get "Open Stock Chart" to work with in iTerm.

    1. That's a pretty simple fix, actually: Download the workflow and open it (do not double-click it to run it, just drag it onto Automator's icon), and up at the top, where it says "Workflow receives current text" in "Terminal" ... click the Terminal drop-down and point it to iTerm instead.

      Then save, double-click and OK to install, and it should work—it did here in testing.

      regards;
      -rob.

  2. Hi Rob,
    I was on the right track, just had not save & double-click to install.
    It is working as it should in iTerm.

    Thank you,
    ABC

Comments are closed.