Integration script for Sonar

I just started using Sonar which is a new GitHub/GitLab issue tracker client available as a TestFlight beta.

I found that the app has a URL scheme, so asked developers if it was implemented, and they were kind enough to give me a brief documentation, just enough to create a starter script for myself.

The URL scheme is composed of the following parts.

sonar-app://open?service=github&owner=madebywindmill&repo=sonar&task=12

My script uses UI scripting which is not ideal, but usable to get the issue URL and title, split URL parts parts, then finally convert it into a Sonar URL.

It is only working with GitHub, but I wanted to share it, so others can develop it further and figure out how to integrate it with GitLab too.

Here’s the script:

use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions

set the clipboard to ""
tell application "System Events"
	repeat 10 times
		tell process "Sonar"
			click menu item "Copy ID & Title" of menu 1 of menu item "Copy" of menu 1 of menu bar item "Edit" of menu bar 1
		end tell
		delay 0.1
		
		set theTitle to (the clipboard as text)
		if theTitle is not missing value and theTitle is not equal to "" then
			exit repeat
		end if
	end repeat
end tell

set the clipboard to ""
tell application "System Events"
	repeat 10 times
		tell process "Sonar"
			click menu item "Copy URL" of menu 1 of menu item "Copy" of menu 1 of menu bar item "Edit" of menu bar 1
		end tell
		delay 0.1
		
		set theURL to (the clipboard as text)
		if theURL is not missing value and theURL is not equal to "" then
			
			exit repeat
		end if
	end repeat
end tell

set serviceName to ""
if theURL contains "github" then
	set serviceName to "github"
end if

-- Extract the owner
set AppleScript's text item delimiters to "/"
set URLPath to the text items of theURL
set ownerName to item 4 of URLPath

-- Extract the repo name
set repoName to item 5 of URLPath

-- Extract the task number
set taskNumber to item 7 of URLPath

"[" & theTitle & "](" & "sonar-app://open?service=" & serviceName & "&owner=" & ownerName & "&repo=" & repoName & "&task=" & taskNumber & ")"
1 Like