# A Touchy Subject

**URL:** <https://forum.beeminder.com/t/a-touchy-subject/6818>\
**Category:** Tech\
**Created:** [May 28, 2020, 10:03am UTC](https://forum.beeminder.com/t/a-touchy-subject/6818 "2020-05-28T10:03:27Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![phi](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.beeminder.com/phi/32/2586_2.png) [@phi](https://forum.beeminder.com/u/phi)\
**Post date:** [May 28, 2020, 10:03am UTC](https://forum.beeminder.com/t/a-touchy-subject/6818/1 "2020-05-28T10:03:27Z")

</div>

I made a thing:

 ![image](https://us1.discourse-cdn.com/flex019/uploads/beeminder/original/2X/5/56113d150a2fe7d16268486fd6ba733f72eb0467.jpeg)

Who knew you could make the touchbar actually do something useful!  
It refreshes every 60s. I could put other goals there, but my goal [spiht](https://www.beeminder.com/phi/spiht) is by far the largest, requiring 4hrs of work each day.

---

<div class="post-metadata">

**Author:** ![phi](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.beeminder.com/phi/32/2586_2.png) [@phi](https://forum.beeminder.com/u/phi)\
**Post date:** [May 28, 2020, 11:55am UTC](https://forum.beeminder.com/t/a-touchy-subject/6818/2 "2020-05-28T11:55:45Z")

</div>

I found a more appropriate field in the API, so now it looks like this:

 ![image](https://us1.discourse-cdn.com/flex019/uploads/beeminder/original/2X/6/6322e3f92681c0ed99422f83a593eeefdfb03ff2.png)

---

<div class="post-metadata">

**Author:** ![adamwolf](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.beeminder.com/adamwolf/32/484_2.png) [@adamwolf](https://forum.beeminder.com/u/adamwolf)\
**Post date:** [May 28, 2020, 2:00pm UTC](https://forum.beeminder.com/t/a-touchy-subject/6818/3 "2020-05-28T14:00:57Z")

</div>

You definitely should be using safesum for this! (Is that an extra space before the 6, or some fancy font spacing, or do I just need to sleep?)

---

<div class="post-metadata">

**Author:** ![phi](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.beeminder.com/phi/32/2586_2.png) [@phi](https://forum.beeminder.com/u/phi)\
**Post date:** [May 28, 2020, 2:12pm UTC](https://forum.beeminder.com/t/a-touchy-subject/6818/4 "2020-05-28T14:12:26Z")

</div>

> [@adamwolf](#):
>
> You definitely should be using safesum for this!

Definitely! That’s the “more appropriate” field I switched to 🙂

> [@adamwolf](#):
>
> (Is that an extra space before the 6, or some fancy font spacing, or do I just need to sleep?)

Indeed! Interesting. ~~I do not know why the font is rendering this way. And that’s not just a screenshot thing – it’s rendered like this on the touchbar as well.~~ Nicely observed!

Addendum: There is actually an additional space in the JSON of `.safesum`:

```json
"+02:56 hours due by 8pm"

```

And [once again for the renegade master](https://www.youtube.com/watch?v=-fLgCjHC6iA):

```shell
{ echo -n 'SPIHT: ' & curl 'https://www.beeminder.com/api/v1/users/me/goals/spiht.json?auth_token=DEADBEEF&datapoints=false' 2> /dev/null | /usr/local/bin/jq '.safesum'; } | tr -d '\n' | tr -s ' '

```

This is the code I am using and which now takes care of the superfluous space that is returned by the API. This gets passed to a `bash -c` and the resulting string is then displayed in my Mac’s touchbar. I could instead return JSON which would allow me to dynamically change the text’s color, background, icon, … There is a lot of opportunity here. If interested I can export the whole thing for other users of BetterTouchTool (which is what is doing the touchbar magic)

---

<div class="post-metadata">

**Author:** ![narthur](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.beeminder.com/narthur/32/5113_2.png) [@narthur](https://forum.beeminder.com/u/narthur)\
**Post date:** [May 28, 2020, 3:35pm UTC](https://forum.beeminder.com/t/a-touchy-subject/6818/5 "2020-05-28T15:35:04Z")

</div>

Wow… How do you put the text to the touch bar?

---

<div class="post-metadata">

**Author:** ![phi](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.beeminder.com/phi/32/2586_2.png) [@phi](https://forum.beeminder.com/u/phi)\
**Post date:** [May 28, 2020, 4:09pm UTC](https://forum.beeminder.com/t/a-touchy-subject/6818/6 "2020-05-28T16:09:57Z")

</div>

With [BetterTouchTool](https://folivora.ai) 🙂  
It’s the swiss army knife for doing stuff like this.  
Fun fact: it’s made by a single person in Germany, actually only two hours away from here.

---

<div class="post-metadata">

**Author:** ![adamwolf](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.beeminder.com/adamwolf/32/484_2.png) [@adamwolf](https://forum.beeminder.com/u/adamwolf)\
**Post date:** [May 28, 2020, 7:03pm UTC](https://forum.beeminder.com/t/a-touchy-subject/6818/7 "2020-05-28T19:03:53Z")

</div>

When you get safesum for that goal, does it have the appropriate number of spaces?

---

<div class="post-metadata">

**Author:** ![phi](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.beeminder.com/phi/32/2586_2.png) [@phi](https://forum.beeminder.com/u/phi)\
**Post date:** [May 28, 2020, 7:20pm UTC](https://forum.beeminder.com/t/a-touchy-subject/6818/8 "2020-05-28T19:20:21Z")

</div>

No, it does not:

```json
"+03:59 hours due by 8pm"

```

---

<div class="post-metadata">

**Author:** ![phi](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.beeminder.com/phi/32/2586_2.png) [@phi](https://forum.beeminder.com/u/phi)\
**Post date:** [May 29, 2020, 4:20pm UTC](https://forum.beeminder.com/t/a-touchy-subject/6818/9 "2020-05-29T16:20:41Z")

</div>

I integrated RescueTime and everything got an icon now 🙂

 ![image](https://us1.discourse-cdn.com/flex019/uploads/beeminder/original/2X/d/da7c89518ef231cc7809a8866d1c6f28adc5eaa9.png)

(The now properly looking spacing in the `safesum` is because of `tr -s ' '`)

---

<div class="post-metadata">

**Author:** ![phi](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.beeminder.com/phi/32/2586_2.png) [@phi](https://forum.beeminder.com/u/phi)\
**Post date:** [May 29, 2020, 5:50pm UTC](https://forum.beeminder.com/t/a-touchy-subject/6818/10 "2020-05-29T17:50:13Z")

</div>

Turns out, RescueTime does not provide today’s productivity pulse, but only that of the past 14 days via their API. At first I thought that today would be included in that list, but no. It starts with yesterday. Which is what my touchbar is showing: Yesterday’s productivity pulse. No wonder it’s not changing 🤪 🤦‍♂️  
That’s surprising giving that the current day’s pulse is the first thing you see on the dashboard and is also the only thing you see when you resize the window small enough.

However, they do provide a way to look at past events:

```http
GET https://www.rescuetime.com/anapi/data?key={{apiKey}}&perspective=interval&restrict_kind=productivity&interval=hour&restrict_begin=2020-05-29&restrict_end=2020-05-29&format=json

```

which gives you this:

```json
{
  "notes": "data is an array of arrays (rows), column names for rows in row_headers",
  "row_headers": [
    "Date",
    "Time Spent (seconds)",
    "Number of People",
    "Productivity"
  ],
  "rows": [
    [
      "2020-05-29T00:00:00",
      129,
      1,
      1
    ],
    [
      "2020-05-29T10:00:00",
      845,
      1,
      2
    ],
    [
      "2020-05-29T10:00:00",
      19,
      1,
      1
    ],
    …

```

I assume I can get a productivity pulse out of that myself since it’s just the average. Some quick and dirty Scala:

```auto
val productivitiesTimesSeconds = for {
  (_, seconds, _, productivity) <- rows
} yield seconds * productivity

val avg = Try(productivitiesTimesSeconds.sum / productivitiesTimesSeconds.length) // because div 0

val secondsRecordedL = for {
  (_, seconds, _, _) <- rows
} yield seconds

val secondsRecorded = secondsRecordedL.sum
val pulse = avg.map(_ / theoreticalMax * 100)

val msg = pulse match {
  case None => "No data logged for today!"
  case Some(p) => s"Your productivity pulse is $p"
}

println(msg)

def theoreticalMax = 2 * secondsRecorded

```

Haven’t tried that, since I actually got stuff to do and this is kinda distracting, but if someone here knows how the productivity pulse is calculated and can tell me if I’m going in the right direction, that would be swell!

---

<div class="post-metadata">

**Author:** ![dbyler](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.beeminder.com/dbyler/32/1936_2.png) [@dbyler](https://forum.beeminder.com/u/dbyler)\
**Post date:** [June 11, 2020, 4:33am UTC](https://forum.beeminder.com/t/a-touchy-subject/6818/11 "2020-06-11T04:33:39Z")

</div>

Glad to see this thread! I’ve been meaning to share my own Beeminder TouchBar widget:

 ![Touch Bar Shot 2020-06-11 at 10.43.15 AM](https://us1.discourse-cdn.com/flex019/uploads/beeminder/original/2X/5/5cc7b351ef0b0bf06ed8d583d318a3365f7102e9.png)

Mine is set up to…

- Only appears while I’m scheduled to derail today (technically within the next 30 hours). Once I’ve cleared all my derailments, the widget disappears.
- Shows the number of goals I’m going to derail on, and the total monetary fine if I derail on all of them. In the screenshot below, I have 3 goals that will derail tonight, for a total of $15.
- Tapping the widget 1) opens my Beeminder page and 2) refreshes the widget
- I have it set to automatically update every 5 minutes, but you can change that in BTT settings

You should be able to install it by downloading the preset here: [https://github.com/dbyler/applescript-misc/raw/master/Beeminder%20Touch%20Bar%20Widget.bttpreset](https://github.com/dbyler/applescript-misc/raw/master/Beeminder%20Touch%20Bar%20Widget.bttpreset)

To configure:

 ![2020-06-11 11-25-13 BetterTouchTool](https://us1.discourse-cdn.com/flex019/uploads/beeminder/original/2X/a/a6f32d3bcb35e770e6174a63e35ac4981091d20a.jpeg)

p.s. In the screenshot, the flag widget to the left of Beeminder shows how many flagged+available items I have in OmniFocus. There’s also a red one that will show up if there are Due items. Happy to share if there’s interest

---

<div class="post-metadata">

**Author:** ![adamwolf](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.beeminder.com/adamwolf/32/484_2.png) [@adamwolf](https://forum.beeminder.com/u/adamwolf)\
**Post date:** [July 1, 2020, 8:46pm UTC](https://forum.beeminder.com/t/a-touchy-subject/6818/12 "2020-07-01T20:46:57Z")

</div>

The extra space should be fixed now.

---

<div class="post-metadata">

**Author:** ![apolyton](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.beeminder.com/apolyton/32/1965_2.png) [@apolyton](https://forum.beeminder.com/u/apolyton)\
**Post date:** [July 2, 2020, 4:23pm UTC](https://forum.beeminder.com/t/a-touchy-subject/6818/13 "2020-07-02T16:23:29Z")

</div>

> [@dbyler](#):
>
> I’ve been meaning to share my own Beeminder TouchBar widget:

Is there something similar for the menu bar for us lower people without touchbars?

---

<div class="post-metadata">

**Author:** ![ken\_vega](https://avatars.discourse-cdn.com/v4/letter/k/e56c9b/32.png) [@ken\_vega](https://forum.beeminder.com/u/ken_vega)\
**Post date:** [July 2, 2020, 11:42pm UTC](https://forum.beeminder.com/t/a-touchy-subject/6818/14 "2020-07-02T23:42:28Z")

</div>

@apolyton I think you mentioned this one before [Beeminder for BitBar?](https://forum.beeminder.com/t/beeminder-for-bitbar/2733)

I actually found your post because of this one and tried BitBar. [There is a plugin for BitBar](https://getbitbar.com/plugins/Web/Beeminder/beeminder.10m.py) I found related to beeminder (also you can check the code in github [here](https://github.com/matryer/bitbar-plugins/blob/584dcb4536b6d0c8b7096d84a6ea08ae516d6c9a/Web/Beeminder/beeminder.10m.py))

Also I tweaked it a bit so it looks like this:

 ![image](https://us1.discourse-cdn.com/flex019/uploads/beeminder/original/2X/8/8d2bcba3c462a0591d9e9ad75210c158074cd673.png)  
shows the nearest goal to derail in the menu bar. But the whole logic is credit for Ben. Thanks a lot Ben if you see this! 😄 [https://getbitbar.com/contributors/bcongdon](https://getbitbar.com/contributors/bcongdon)

This is the code tweaked I have in case you want it:

```auto
#!/usr/bin/python
# -*- coding: utf-8 -*-

# <bitbar.title>Beeminder</bitbar.title>
# <bitbar.version>v1.0</bitbar.version>
# <bitbar.author>Ben Congdon</bitbar.author>
# <bitbar.author.github>bcongdon</bitbar.author.github>
# <bitbar.image>https://i.imgur.com/XamwU1E.png</bitbar.image>
# <bitbar.desc>Displays your active Beeminder goals and their due dates/amounts</bitbar.desc>
# <bitbar.dependencies>python,requests</bitbar.dependencies>

import requests

# NOTE: Change these to set your credentials
USERNAME = 'your_username'
AUTH_TOKEN = 'your_api_key' # you can find it in https://www.beeminder.com/api/v1/auth_token.json

# Don't change anythine below this line
if not USERNAME or not AUTH_TOKEN:
  print('⚠️\n---\nBeeminder: No username and/or auth token provided!')
  exit(1)
API_URL = 'https://www.beeminder.com/api/v1/users/{}.json'.format(USERNAME)

req = requests.get(API_URL, params=dict(auth_token=AUTH_TOKEN, datapoints_count=1, associations=True))

data = req.json()
goals = data['goals']

output = '{} for {}|color={} font=Monaco\n---\n'.format(goals[0]['limsumdate'], goals[0]['slug'], goals[0]['roadstatuscolor'])
  
max_slug_len = max(len(goal['slug']) + 1 for goal in goals)

for goal in goals:
  if goal.get('coasting'):
    continue

  goal_url = 'https://www.beeminder.com/{}/{}'.format(USERNAME, goal['slug'])

  output += "{}".format(goal['limsumdate'].ljust(27)) + " {}".format(goal['slug'].rjust(21)) + "|href={} color={} font=Monaco\n".format(goal_url, goal['roadstatuscolor'])

print(output)

```

I remember I needed to install `requests` package for python using pip. [This article](https://ahmadawais.com/install-pip-macos-os-x-python/) might help you with that.

I’m trying also to get data from Rescuetime now. I found [another plugin for it](https://getbitbar.com/plugins/Dev/RescueTime/rescuetime.1h.py) but I’m looking to get my daily time spent in a particular category instead of my productivity pulse. If you find a way to get that would it be cool!
