Stock/Ticker symbol widget

Does anyone have a working stock widget in 2020 on the Touch Bar? I think it would be so cool to be able to glance down at my Touch Bar and see what the dow is doing without having to open up yahoo finance.
Thanks!

I was able to come up with a custom ticker of sorts. I am using a free API from Alpha Advantage.
I set up an app with Automator to pull the data then using AppleScript I am able to add the data from the local file.

There is a Timed Trigger in BTT to run the app to fetch data. On the far right I have a button to note the modification time of the document so I can monitor the information for relevance. If there is a failure to execute the app then tapping the button will execute manually.

2 Likes

Woah!! That is so cool and exactly what I was looking for! I don't know much about apple script so is there anyway you could make that preset downloadable? Also, it looks like you have it directly linked to your broker so is the preset broker specific ?
Thanks

It's a bit hard to share as it is highly customized to my personal holdings as well as involves a local file created through Automator. I obtain the data by using a free API key from www.alphavantage.co.

The Automator workflow is set up as:
Run Shell Script where I run curl to fetch the data from alpha advantage
New Text File with the checkbox to Replace existing file active in order to have a new file written each time the workflow runs. This allows the applescripts to always pull the correct text from the files.

Here is a sample script to get you started:
set StockSymbol to "" -- enter ticker symbol
set BuyPrice to "" -- enter average buy price

set stockData to "" -- enter path to file
set currentPrice to word 3 of paragraph 20 of (read stockData)
if currentPrice is less than BuyPrice then
return StockSymbol & "- $" & text 1 thru -3 of currentPrice
else
return StockSymbol & return & "$" & text 1 thru -3 of currentPrice
end if

Gotcha, well now I know it is possible lol😂. Time for me to learn how to code !

Everything is possible. Let me know if I can help at all.

I am learning AppleScript as I build out this touchbar :grin:

Ao do you use automator to create your script or a separate program? sorry for the dumb question :sweat_smile:

I used Automator to set up an app which runs curl to alpha advantage and save the data to a local txt document.

From that local file I use AppleScript within the BTT widgets to extract the data and use if statements to change the color of the text based upon gains or losses.

 set StockSymbol to "TICKER SYMBOL"
set BuyPrice to "BUY PRICE"


set stockData to "MY LOCAL FILE"

set currentPrice to word 3 of paragraph 7 of (read stockData)


if currentPrice is less than BuyPrice then
	return StockSymbol & "-   $" & text 1 thru -3 of currentPrice
	
else
	return StockSymbol & return & "$" & text 1 thru -3 of currentPrice
end if

Wow ok sounds good, Thank you so much for taking the time to help me man, I really appreciate it. I can't wait till I figure this out, it will be sweet!

The local file looks like:

{
"Global Quote": {
"01. symbol": "DIS",
"02. open": "117.6000",
"03. high": "118.0000",
"04. low": "112.2500",
"05. price": "112.6400",
"06. volume": "26040809",
"07. latest trading day": "2020-06-11",
"08. previous close": "122.1800",
"09. change": "-9.5400",
"10. change percent": "-7.8082%"
}
}{
"Global Quote": {
"01. symbol": "UAL",
"02. open": "33.2550",
"03. high": "36.3800",
"04. low": "32.2200",
"05. price": "33.3200",
"06. volume": "103258256",
"07. latest trading day": "2020-06-11",
"08. previous close": "39.7200",
"09. change": "-6.4000",
"10. change percent": "-16.1128%"
}
}{
"Global Quote": {
"01. symbol": "ALK",
"02. open": "36.1100",
"03. high": "38.1250",
"04. low": "35.1800",
"05. price": "35.5900",
"06. volume": "6806606",
"07. latest trading day": "2020-06-11",
"08. previous close": "41.4800",
"09. change": "-5.8900",
"10. change percent": "-14.1996%"
}
}{
"Global Quote": {
"01. symbol": "XOM",
"02. open": "47.5300",
"03. high": "48.8400",
"04. low": "46.1000",
"05. price": "46.1800",
"06. volume": "39140649",
"07. latest trading day": "2020-06-11",
"08. previous close": "50.6500",
"09. change": "-4.4700",
"10. change percent": "-8.8253%"
}
}{
"Global Quote": {
"01. symbol": "T",
"02. open": "31.2000",
"03. high": "31.3200",
"04. low": "30.1150",
"05. price": "30.1700",
"06. volume": "49810186",
"07. latest trading day": "2020-06-11",
"08. previous close": "32.1400",
"09. change": "-1.9700",
"10. change percent": "-6.1294%"
}
}

So it took some time to break down exactly which text to extract.

The first step is to go to www.alphaadvantage.co to sign up for their free API. You will need the API key in the URL in order to obtain the data. They allow up to 5 pings per minute for the free.


I am making progress, was able to figure out how to fetch basic data from the api using a basic python script and then running it in terminal :grinning:. now I just need to figure out how to incorporate this information to the Touch Bar :+1:

1 Like

Nicely done! I've never tried working with Python so you're already ahead of me! :joy:

oh no way, i though that you had to use python to to use the api :joy:. it was my first time time using it also (watched a lot of youtube today :joy: ). so you were able to access the api straight through applescript ?

Thank goodness for YouTube!

In Automator there is a Shell action.. in there I just ran "curl THE_URL"
This can be done in AppleScript too but I couldn't figure out how to have the data saved to the file without appending to what was already there.

gotcha, i will give that ago tonight and will keep you updated :laughing:

Hey, so I got the API working in automator and I am able to view it as a .txt file in finder. I have been messing around in BTT for a while and just can't figure out how to pull the data and use it in btt. Are you using the AppleScript widget feature as a trigger, if so what is the assigned action?

Give this a try as a template. In BTT, I am using AppleScript triggers. Using similar scripts I have each widget to open a group for each company with more of a breakdown of the data.

![image|690x20]
![image|690x20]

StockSet.bttpreset (267.0 KB)

ok thanks, that will hopefully give me a better understanding of how you integrate that data into the Touch Bar! Just curious, how did you learn how to write AppleScript and do all this ?

Mostly by downloading other presets here and dissecting their scripts, essentially testing each line. Duckduckgo and StackExchange have been quite helpful resources. I am by no means an expert. I am currently stuck on a few pieces too which are starting to make me insane :joy:

1 Like

wait for real. This will make my life a lot easier. It's so cool, love it. do you mind if copy this code :heart_eyes::sweat_smile:

Imprint | Privacy Policy