GoldenChaos-BTT Support and Feedback Thread

i think it would be better to wrap the whole album art related part of the itunes script in a try statement, because now the widget isn't shown when a song has no album art, because itunes throws an error
here is my quick and dirty fix, it uses a default icon at the same place the album art is temp stored

tell application "System Events"
	set num to count (every process whose name is "iTunes")
end tell
set maxSize to 20

if num > 0 then
    
	try
		tell application "iTunes" to tell artwork 1 of current track
			set srcBytes to raw data
			-- figure out the proper file extension
			if format is «class PNG » then
				set ext to ".png"
			else
				set ext to ".jpg"
			end if
		end tell
	    
	    
		set fileName to ((((path to application support folder from user domain) as text) & "BetterTouchTool:" as text) & "itunes_cover" & ext)
		-- write to file
		set outFile to open for access file fileName with write permission
		-- truncate the file
		set eof outFile to 0
		-- write the image bytes to the file
		write srcBytes to outFile
		close access outFile
	on error
		set filename to ((((path to application support folder from user domain) as text) & "BetterTouchTool:" as text) & "default.png")
	end try
    
	tell application "iTunes"
		set playState to (player state as text)
		if playState is equal to "playing" then
			set trackName to name of current track
			set artistName to artist of current track
			set albumName to album of current track
			if length of trackName is greater than maxSize then
				set trackName to text 1 thru (maxSize - 3) of trackName & "..."
			end if
			if length of artistName is greater than maxSize then
				set artistName to text 1 thru (maxSize - 3) of artistName & "..."
			end if
			set trackInfo to artistName & " - " & trackName
		else
			set trackInfo to "Paused"
		end if
		return "{\"text\":\"" & trackInfo & "\",\"icon_path\":\"" & (POSIX path of fileName as text) & "\"}"
	end tell
else
	return ""
end if
1 Like

I'll incorporate this into my preset with the next release :slight_smile: thanks for the fix!

1 Like

Any ideas on how to alter that Things 3 script to work with Todoist? I know TD has a rather robust web API, and I'm hoping I can do something similar to what you've got going with Things. Thanks!

another very small fix, in the youtube widget script if only safari is running but not youtube the script doesn't return, this causes the widget to continue showing the last youtube clip, even if that tab is already closed. I added a return statement after the loop, at the end of the safari clause to make sure it always returns something

if application "iTunes" is running then
    return ""
else if application "Spotify" is running then
    return ""
else if application "Safari" is running then
    tell application "Safari"
        repeat with t in tabs of windows
            tell t
                if URL starts with "https://www.youtube.com/watch" then
                    return name of t as text
                end if
            end tell
        end repeat
    end tell
    return ""
else
    return ""
end if
1 Like

Ooh! Have you been able to work out a hierachy player script?! Must play around soon!

Also interested in this! I currently use a shortcut to add to my Todoist, but would love to get a display going. I was thinking of working with IFTTT, creating a Dropbox file then reading that through BTT. Again quite a large workaround, but it might be worth exploring as it'd create a ton of possibilities for other IFTTT services...

I've got some other projects going on, so for now I can't look to much into this.

My biggest issue has been gaining access to Dropbox folder.
Here's the script if you want to try?

tell application "System Events"
set the_folder to path to folder "dropbox" from user domain as string
set the_file to "ToDo.txt" of (POSIX path of the_folder)
set the_text to (do shell script "cat " & quoted form of (POSIX path of the_file))
return the_text
end tell

** edit: Script was way off:

tell application "System Events"
set the_folder to the folder "~/Dropbox"
set the_file to the file "ToDo.txt" in the_folder

set the_text to do shell script "cat " & ¬
quoted form of (POSIX path of the_file as text)
end tell

return the_text

** Edit again. I've made a tutorial that's a lot cleaner.

It still uses multiple widgets each with their own conditional statements. I might try combining them into one widget in the future, but then you'd lose all the nice custom app icons.

As for todoist, I don't personally use it and I'm not familiar with their API, but if you guys manage to get something working I'll include it in the preset :slight_smile:

Hi @GoldenChaos this is truly amazing. I appreciate all the work you did with this.

  1. Is there a way to include the Do Not Disturb icon for immediate access? Is the only action that I currently use with the stock (and terrible) touch bar.

  2. Is there a way to switch Farenheit to Celsius on the weather widget?

Many thanks in advance, and congratulations on the hard work.

1 Like

I'm glad you're enjoying the preset :slight_smile: to answer your questions:

  • There is a Do Not Disturb toggle in the expanded control strip - just hold down the Option key, it's next to Night Shift. Most every button available on the stock control strip is there, plus some extras!
  • If you edit the weather widget, you'll find a line for Celcius conversion commented out. Just uncomment it and bam! SI units.

Amaaazing.

I didn't find the commented piece but on this part:

set weather to fetch JSON from "http://api.openweathermap.org/data/2.5/weather?lat=" & item 1 of clocation_coords & "&lon=" & item 2 of clocation_coords & "&units=metric&appid=32c4256d09a4c52b38aecddba7a078f6"

I did the switch on the units.

Ah, you're on an older version! My bad. I'm guessing you're on the main release (2.513). Glad you figured it out, haha :stuck_out_tongue:

Not necessarily :slight_smile:

Right click the applications - show package - resources - and copy out their app icons.

I do this if I can't pull an artwork from iTunes

As for Todoist, I've gone a longer route through IFTTT and Dropbox. Probably not something to include in the overall preset as there are quite a few manual settings each user would need to do. But it might help anyone personally. As it doesn't just have to be Todoist.

Oh, I'm gonna update now then. I've downloaded the one you have in your initial post and I thought that was the latest version.

I'm having an issue with the weather widget now. Getting the following error:

Traceback (most recent call last):
File "", line 3, in
ImportError: No module named requests

And getting this on the iCal one:

2018-06-27 16:16:27.263 icalBuddy[20300:3713478] Error loading /System/Library/PrivateFrameworks/CalendarFoundation.framework/CalendarFoundation: dlopen(/System/Library/PrivateFrameworks/CalendarFoundation.framework/CalendarFoundation, 265): no suitable image found. Did find:
/System/Library/PrivateFrameworks/CalendarFoundation.framework/CalendarFoundation: mach-o, but wrong architecture
/System/Library/PrivateFrameworks/CalendarFoundation.framework/Versions/A/CalendarFoundation: mach-o, but wrong architecture

With the main release weather and calendar events work fine.

Working on a fix for Calendar, will have it posted shortly. Weather widget is a new version using the Dark Sky API and LocateMe since JSON/Location Helper don't work on Mojave. The Python module "requests" is also required for this new weather widget to work, and that's the part you don't seem to have installed. Install with pip install requests and it should work :slight_smile:

I'm running into an issue with what I'm assuming is caused by the weather widget (I am using the latest 2.526 goldenchaos on 2.530 BTT -- which might be the reason).

What happens is after a period of time (usually when the computer goes to sleep and I log back on), the entire touchbar is black to the left of the search button. The same happens when holding down option. Disabling the weather script for both restores everything back to normal.

Anyone else running into that issue?

This is what happens when the weather script can’t get any weather data (such as when there is no network connection). I’ll see how to add better error handling to the script so that doesn’t happen. Restarting BTT will fix it if you’ve restored network access.

That did the trick. Thanks for the reply!

1 Like

The weather script was working fine until this afternoon where I started getting the following error:

Traceback (most recent call last):
  File "<string>", line 6, in <module>
  File "/Users/chompas/Library/Python/2.7/lib/python/site-packages/requests/models.py", line 896, in json
    return complexjson.loads(self.text, **kwargs)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/__init__.py", line 338, in loads
    return _default_decoder.decode(s)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/decoder.py", line 366, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/decoder.py", line 384, in raw_decode
    raise ValueError("No JSON object could be decoded")
ValueError: No JSON object could be decoded

Any ideas? @GoldenChaos

Unfortunately it's a limitation of the Dark Sky API. I only get 1000 requests per day, so I have been working on lowering the number of requests the preset uses. Unfortunately, the weather widget appears in multiple locations, and it wouldn't look good to selectively hide the weather widget. It also wouldn't fix the underlying issue of only having 1000 requests, womp.

I would love to use a service that doesn't have a limit, but there doesn't seem to be one that's reliable. I'm open to suggestions, and in the meantime I'll work on further reducing the number of API calls it uses.

Ah, that makes sense. I had the same issue in the past with weather APIs. Will ping you if I find a good alternative.