Skip to content

Instantly share code, notes, and snippets.

@Ullaakut
Last active Oct 17, 2018
Embed
What would you like to do?
The applescript code for the travisCI widgets
# Replace those with your repository IDs
set BloggoID to "20418060"
set CameradarID to "10999701"
set RTSPattID to "10999702"
set GonveyID to "21157116"
# Gets status from Travis API
on getStatus(repositoryID)
set status to do shell script "curl -v -H \"Travis-API-Version: 3\" \"https://api.travis-ci.org/repo/" & repositoryID & "/builds?limit=1\" | grep -Eo '\"state\":.*?[^\\]\",' | awk -F':' '{print $2}' | sed 's/[\", ]//g'"
return status
end getStatus
# Sets the animation variable accordingly
# 1 = dancing
# 0 = paused
# -1 = error
on setGopher(status)
set err to "errored"
set failure to "failed"
set created to "created"
set inProgress to "started"
tell application "BetterTouchTool"
if status is equal to err then
set_persistent_number_variable "anim-output-color--running" to -1
return "err"
else if status is equal to failure then
set_persistent_number_variable "anim-output-color--running" to -1
return "err"
else if status is equal to inProgress then
set_persistent_number_variable "anim-output-color--running" to 1
return "dance"
else if status is equal to created then
set_persistent_number_variable "anim-output-color--running" to 1
return "dance"
else
set_persistent_number_variable "anim-output-color--running" to 0
return status
end if
end tell
end setGopher
set success to "passed"
# Repeat these lines for your repositories as necessary
set BloggoStatus to getStatus(BloggoID)
setGopher(BloggoStatus)
if BloggoStatus is not equal to success then
return BloggoStatus
end if
set CameradarStatus to getStatus(CameradarID)
setGopher(CameradarStatus)
if CameradarStatus is not equal to success then
return CameradarStatus
end if
set RTSPattStatus to getStatus(RTSPattID)
setGopher(RTSPattStatus)
if RTSPattStatus is not equal to success then
return RTSPattStatus
end if
set GonveyStatus to getStatus(GonveyID)
setGopher(GonveyStatus)
if GonveyStatus is not equal to success then
return GonveyStatus
end if
return "all good"
tell application "BetterTouchTool"
set numFrames to 23
set startFrame to 0
set basePath to "/Users/ullaakut/Documents/Experiments/gopher/"
set baseName to "output-color-"
set extension to ".png"
set widgetId to "22D46B72-12F1-4C63-BED5-6D59B6502B8D"
set errorFilePath to basePath & "output-failure" & extension
set runningVarName to "anim-" & baseName & "-running"
try
set running_anim to ((get_number_variable runningVarName) as integer)
on error
set running_anim to 0
end try
set fullFilePath to ""
if running_anim = 1 then
set varName to "anim-" & baseName & "frame"
try
set frame to ((get_number_variable varName) as integer)
on error
set frame to startFrame
end try
if frame > numFrames then
set frame to startFrame
end if
set_persistent_number_variable varName to frame + 1
set fileName to baseName & (frame as string) & extension
set fullFilePath to basePath & fileName
update_touch_bar_widget widgetId text "Gopher dance" icon_path fullFilePath
return "dance"
else if running_anim = -1 then
update_touch_bar_widget widgetId text "Gopher dance" icon_path errorFilePath
return "error"
end if
end tell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment