Help needed for Handoff Script

touch-bar
handoff
#1

Hi together,

So, I have this great piece of code that displays notifications and the handoff status of some of my apps right in my Touch Bar. I gave an icon with a red dot as standard icon, and the normal icon as secondary icon that displays when the widget returns " ". For handoff, I created the icons by myself and added them into the script by using base64. Here is what it looks like: New Mail, and handoff for the iPhone in messages.


Now this works great with Messages, but I encounter some trouble with Mail as all the results just displays a red dot (basically do not have " " as result and keep the red dot icon so).
Notes is particularly messed up…
With handoff activated on the iPhone it just disappears, with handoff activated fro the iPad it turns just totally blue (what is the standard background, but then why is there no icon - it's saved independently to the script).

Maybe some of you could give me a little hint on what's messing up my script? Thanks already!
Find attached a preset with the scripts (can't post the scripts only due to number of character limitation), with the messages, notes, and mail widgets. Once I understood where I'm wrong I hope being able to extrapolate them also to Safari, reminders, and PDF Expert by myself!

Handoff Preset with messing icons.bttpreset (810.2 KB)

@Andreas_Hegenberg: maybe this is a trouble in the latest alphas? Or did I just copy-paste in an incorrect way what Base64 gave me (I chose the "For use in img elements"). Thanks once more :+1:t3:

1 Like

#2

Read a bit before and after for some context if you wish. My ones seem to be working pretty well

0 Likes

#3

Thank you! I was looking for this thread but didn't find it!

In the meantime I made this template script for handoff apps:

if application "APPLICATION_HERE" is running then
tell application "System Events"
	tell process "Dock"
		try
			set badgeNumber to value of attribute "AXStatusLabel" of UI element "APPLICATION_HERE" of list 1
			if badgeNumber exists then
				if badgeNumber contains "iPhone" then
					return "{\"text\":\"iPhone\", \"icon_data\": \"iPHONE_ICON_HERE\"}"
				else if badgeNumber contains "iPad" then
					return "{\"text\":\"iPad\", \"icon_data\": \"iPAD_ICON_HERE\"}"
				else if badgeNumber contains "Mac" then
					return "{\"text\":\"Mac\", \"background_color\": \"235,235,235,70\"}"
				else if badgeNumber contains "watch" then
					return "{\"text\":\"watch\", \"icon_data\": \"watch_ICON_HERE\"}"
				else
					return "{\"text\":\"Notification\", \"icon_data\": \"NOTIFICATION_ICON_HERE\"}"
				end if
			else
				return "{\"text\":\"Native\", \"icon_data\": \"NORMAL_ICON_HERE\"}"
			end if
		on error
			return "error"
		end try
	end tell
end tell
else
    return "{\"text\":\"Native\", \"icon_data\": \"NORMAL_ICON_HERE\"}"
end if
0 Likes

#4

This method was the old one we used and ate up a lot of CPU, draining the battery. We got a new applescript command from @Andreas_Hegenberg that does some efficiency magic and uses much less power. Have a read of that thread!

1 Like

#5

It's on my list, probably during the weekend or so :wink:

0 Likes

#6

Weekend came early.
I used the new way (thanks again) with the personalised handoff icons. :slight_smile:

0 Likes