Handoff Widget.

Yuppee ya hey Community :smiley:

So, I got bored. I recently replaced my widgets that display notification dots through the new dock widget, and was left behind w/o the handoff icons. Don't like it.

So I created an easy widget that will appear only if a handoff icon is detected! By default it contains

  • Mail
  • Messages
  • Notes
  • Reminders
  • Fantastical
  • PDF Expert
  • Safari

With the iPhone, iPad and watchOS icon, but it can be extended by any other app!

Here is the script w/o the Base64 icons:

tell application "BetterTouchTool"
	try
		set dndEnabled to get_number_variable "SystemDoNotDisturbState"
	end try
end tell

if dndEnabled is 0 then
	tell application "BetterTouchTool"
		
		set handoffDeviceMail to get_dock_badge_for "Mail-handoff" update_interval 3
		set handoffDeviceMessages to get_dock_badge_for "Messages-handoff" update_interval 3
		set handoffDeviceNotes to get_dock_badge_for "Notes-handoff" update_interval 3
		set handoffDeviceReminders to get_dock_badge_for "Safari-handoff" update_interval 3
		set handoffDeviceFantastical to get_dock_badge_for "Fantastical-handoff" update_interval 3
		set handoffDevicePDFExpert to get_dock_badge_for "PDFExpert-handoff" update_interval 3
		set handoffDeviceSafari to get_dock_badge_for "Safari-handoff" update_interval 3
		
		
		if handoffDeviceMail is not missing value then
			if handoffDeviceMail contains "iPhone" then
				set returnvalue to "{\"text\":\"iPhone\", \"icon_data\": \"iPHONE_ICON_HERE\"}"
			else if handoffDeviceMail contains "iPad" then
				set returnvalue to "{\"text\":\"iPad\", \"icon_data\": \"iPAD_ICON_HERE\"}"
			else if handoffDeviceMail contains "watch" then
				set returnvalue to "{\"text\":\"watch\", \"icon_data\": \"watch_ICON_HERE\"}"
			end if
			
		else if handoffDeviceMessages is not missing value then
			if handoffDeviceMessages contains "iPhone" then
				set returnvalue to "{\"text\":\"iPhone\", \"icon_data\": \"iPHONE_ICON_HERE\"}"
			else if handoffDeviceMessages contains "iPad" then
				set returnvalue to "{\"text\":\"iPad\", \"icon_data\": \"iPAD_ICON_HERE\"}"
			else if handoffDeviceMessages contains "watch" then
				set returnvalue to "{\"text\":\"watch\", \"icon_data\": \"watch_ICON_HERE\"}"
			end if
			
		else if handoffDeviceNotes is not missing value then
			if handoffDeviceNotes contains "iPhone" then
				set returnvalue to "{\"text\":\"iPhone\", \"icon_data\": \"iPHONE_ICON_HERE\"}"
			else if handoffDeviceNotes contains "iPad" then
				set returnvalue to "{\"text\":\"iPad\", \"icon_data\": \"iPAD_ICON_HERE\"}"
			end if
			
		else if handoffDeviceReminders is not missing value then
			if handoffDeviceReminders contains "iPhone" then
				set returnvalue to "{\"text\":\"iPhone\", \"icon_data\": \"iPHONE_ICON_HERE\"}"
			else if handoffDeviceReminders contains "iPad" then
				set returnvalue to "{\"text\":\"iPad\", \"icon_data\": \"iPAD_ICON_HERE\"}"
			else if handoffDeviceReminders contains "watch" then
				set returnvalue to "{\"text\":\"watch\", \"icon_data\": \"watch_ICON_HERE\"}"
			end if
			
		else if handoffDeviceFantastical is not missing value then
			if handoffDeviceFantastical contains "iPhone" then
				set returnvalue to "{\"text\":\"iPhone\", \"icon_data\": \"iPHONE_ICON_HERE\"}"
			else if handoffDeviceFantastical contains "iPad" then
				set returnvalue to "{\"text\":\"iPad\", \"icon_data\": \"iPAD_ICON_HERE\"}"
			else if handoffDeviceFantastical contains "watch" then
				set returnvalue to "{\"text\":\"watch\", \"icon_data\": \"watch_ICON_HERE\"}"
			end if
			
		else if handoffDevicePDFExpert is not missing value then
			if handoffDevicePDFExpert contains "iPhone" then
				set returnvalue to "{\"text\":\"iPhone\", \"icon_data\": \"iPHONE_ICON_HERE\"}"
			else if handoffDevicePDFExpert contains "iPad" then
				set returnvalue to "{\"text\":\"iPad\", \"icon_data\": \"iPAD_ICON_HERE\"}"
			end if
			
		else if handoffDeviceSafari is not missing value then
			if handoffDeviceSafari contains "iPhone" then
				set returnvalue to "{\"text\":\"iPhone\", \"icon_data\": \"iPHONE_ICON_HERE\"}"
			else if handoffDeviceSafari contains "iPad" then
				set returnvalue to "{\"text\":\"iPad\", \"icon_data\": \"iPAD_ICON_HERE\"}"
			end if
		else
			set returnvalue to ""
		end if
	end tell
else
	return ""
end if

return returnvalue

To add an Application:
Add the line

set handoffDeviceYOUR_APP to get_dock_badge_for "Safari-handoff" update_interval 3

At the beginning of the script.
Then, add a block

		else if handoffDeviceYOUR_APP is not missing value then
			if handoffDeviceYOUR_APP contains "iPhone" then
				set returnvalue to "{\"text\":\"iPhone\", \"icon_data\": \"iPHONE_ICON_HERE\"}"
			else if handoffDeviceYOUR_APP contains "iPad" then
				set returnvalue to "{\"text\":\"iPad\", \"icon_data\": \"iPAD_ICON_HERE\"}"
			else if handoffDeviceYOUR_APP contains "watch" then
				set returnvalue to "{\"text\":\"watch\", \"icon_data\": \"watch_ICON_HERE\"}"
			end if

After the first block (between Mail and Messages)
Don't forget to paste your icons in base64 format!!



The script that must be executed if the widget is touched is the following:

tell application "BetterTouchTool"
	
	set handoffDeviceMail to get_dock_badge_for "Mail-handoff" update_interval 3
	set handoffDeviceMessages to get_dock_badge_for "Messages-handoff" update_interval 3
	set handoffDeviceNotes to get_dock_badge_for "Notes-handoff" update_interval 3
	set handoffDeviceReminders to get_dock_badge_for "Safari-handoff" update_interval 3
	set handoffDeviceFantastical to get_dock_badge_for "Fantastical-handoff" update_interval 3
	set handoffDevicePDFExpert to get_dock_badge_for "PDFExpert-handoff" update_interval 3
	set handoffDeviceSafari to get_dock_badge_for "Safari-handoff" update_interval 3
	
	
	if handoffDeviceMail is not missing value then
		tell application "System Events"
			tell process "Dock"
				try
					click UI element "Mail" of list 1
				end try
			end tell
		end tell
		
	else if handoffDeviceMessages is not missing value then
		tell application "System Events"
			tell process "Dock"
				try
					click UI element "Messages" of list 1
				end try
			end tell
		end tell
		
	else if handoffDeviceNotes is not missing value then
		tell application "System Events"
			tell process "Dock"
				try
					click UI element "Notes" of list 1
				end try
			end tell
		end tell
		
	else if handoffDeviceReminders is not missing value then
		tell application "System Events"
			tell process "Dock"
				try
					click UI element "Reminders" of list 1
				end try
			end tell
		end tell
		
	else if handoffDeviceFantastical is not missing value then
		tell application "System Events"
			tell process "Dock"
				try
					click UI element "Fantastical" of list 1
				end try
			end tell
		end tell
		
	else if handoffDevicePDFExpert is not missing value then
		tell application "System Events"
			tell process "Dock"
				try
					click UI element "PDF Expert" of list 1
				end try
			end tell
		end tell
		
	else if handoffDeviceSafari is not missing value then
		tell application "System Events"
			tell process "Dock"
				try
					click UI element "Safari" of list 1
				end try
			end tell
		end tell
	end if
end tell

Once again, add the line

set handoffDeviceYOUR_APP to get_dock_badge_for "Safari-handoff" update_interval 3

And now the block

	else if handoffDeviceYOUR_APP is not missing value then
		tell application "System Events"
			tell process "Dock"
				try
					click UI element "YOUR_APP" of list 1
				end try
			end tell
		end tell



And that's it! :slightly_smiling_face:

Find attached the widget containing the icons for

  • Mail
  • Messages
  • Notes
  • Reminders
  • Fantastical
  • PDF Expert
  • Safari

Handoff Widget.json (1.4 MB)