Skip to content

Instantly share code, notes, and snippets.

@brantwedel
Last active October 4, 2018 02:58
Show Gist options
  • Save brantwedel/db3f231c6d63ac677972e9be5f90aef6 to your computer and use it in GitHub Desktop.
Save brantwedel/db3f231c6d63ac677972e9be5f90aef6 to your computer and use it in GitHub Desktop.
TouchBar "Dock" using Better Touch Tool
# cycle through Google Chrome tabs and windows
tell application "System Events"
set activeApp to name of first application process whose frontmost is true
try
set activeChrome to first application process whose name is "Google Chrome"
set appName to name of window 1 of activeChrome
on error errMsg
tell application "Google Chrome" to make new window
tell application "Google Chrome" to activate
return
end try
if "Google Chrome" is not in activeApp then
tell application "Google Chrome" to activate
return
end if
end tell
tell application "Google Chrome"
set firstWIndow to -1
set firstIndex to -1
set nextWindow to -1
set nextIndex to -1
repeat with w in windows
set i to 1
set found to -1
repeat with t in tabs of w
# if URL of t starts with "" then
if firstWIndow is equal to -1 then
set firstWIndow to w
set firstIndex to i
end if
if (i is greater than active tab index of w or w is not firstWIndow) and nextWindow is equal to -1 then
set nextWindow to w
set nextIndex to i
end if
# end if
set i to i + 1
end repeat
end repeat
if nextWindow is not -1 then
set active tab index of nextWindow to nextIndex
set index of nextWindow to 1
return
end if
if firstWIndow is not -1 then
set active tab index of firstWIndow to firstIndex
set index of firstWIndow to 1
return
end if
end tell
try
tell application "System Events"
set activeApp to name of first application process whose frontmost is true
if "Google Chrome" is activeApp then
return " "
else
return activeApp
end if
end tell
end try
return " "
# check if Finder is active, change for desired app
try
tell application "System Events"
set activeApp to name of first application process whose frontmost is true
if "Finder" is activeApp then
return " "
end if
end tell
end try
return " "
# check if slack is active, or if there are unread messages
use framework "Foundation"
set t to (current application's NSDate's timeIntervalSinceReferenceDate) as real
set blinkRate to 0.75
set t to t mod (blinkRate * 2) - blinkRate
try
tell application "System Events"
set badge_value to " "
tell process "Dock"
set badge_value to value of attribute "AXStatusLabel" of UI element "Slack" of list 1 of application process "Dock" of application "System Events" as text
if badge_value is not equal to "missing value" then
if t is greater than 0 then
return " "
else
return " "
end if
end if
end tell
set activeApp to name of first application process whose frontmost is true
if "Slack" is activeApp then
return " "
end if
end tell
end try
return " "
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment