Integration script for Linear

Hi!

I’m exploring Hookmark specifically for linking items in Linear to other apps, particularly Obsidian.

I mostly use the Linear desktop app, on Mac.

I’ve come up with the following script for “Get address”. It relies on UI automation as I haven’t found another way to discover the current open item in Linear. (I’ve started a thread on their Slack forum)

delay 0.1
set the clipboard to ""
delay 0.2

tell application "System Events" to tell process "Linear"
    keystroke "," using {command down, shift down}
    delay 0.5
    
    repeat 50 times -- poll clipboard for ~2.5 seconds
        try
            if (the clipboard) is not equal to "" then
                exit repeat
            end if
        end try
        delay 0.05
    end repeat
    
end tell
set issueUrl to the clipboard

-- Check if the Linear application is running
set useDesktopURL to false
tell application "System Events"
    set appList to (name of every process)
    if appList contains "Linear" then
        set useDesktopURL to true
    end if
end tell

if useDesktopURL then
    -- Extract team and issue ID from the web URL
    set AppleScript's text item delimiters to "/"
    set urlComponents to text items of issueUrl
    set team to item 4 of urlComponents
    set issueID to item 6 of urlComponents

    -- Format the desktop URL
    set desktopIssueUrl to "linear://" & team & "/issue/" & issueID
end if

tell application "System Events"
    tell process "Linear"
        set issueTitle to name of window 1
    end tell
end tell

if useDesktopURL then
    return "[" & issueTitle & "](" & desktopIssueUrl & ")"
else
    return "[" & issueTitle & "](" & issueUrl & ")"
end if

I hope this helps someone. Feedback and complete rewrites :grinning: welcome.

1 Like

Thank you very much for the script, @man8louis .

I will take the following script out because the get Address script is only called when the Linear Desktop app is running. Correct me if this is wrong. I am not familiar Linear.

Indeed, thank you. It seems I didn’t quite think that through.