thomaskekeisen.de

From the life of a screen worker

Optimized workflow

In my company Lulububu we follow the rule, that every email we send to a customer also contains the JIRA issue key in the subject, like the mails from JIRA you get when an issue you are watching got an update. Since I lost a lot of time clicking on the issue link or copying the issue key to my browsers URL to open the issue in our JIRA cloud instance, I wrote a small BetterTouchTool script that automatically opens the issue related to the mail you are currently viewing in the macOS mail app.

            
                # https://stackoverflow.com/questions/997828/is-there-something-akin-to-regex-in-applescript-and-if-not-whats-the-alternat
                on getMatch(s, regex)
                    local ignoreCase, extraCommand
                    set ignoreCase to "a" is "A"
                    if ignoreCase then
                        set extraCommand to "shopt -s nocasematch; "
                    else
                        set extraCommand to ""
                    end if
                    tell me to do shell script "export LANG='" & user locale of (system info) & ".UTF-8'; shopt -s compat31; " & extraCommand & "[[ " & quoted form of s & " =~ " & quoted form of regex & " ]] && printf '%s\\n' \"${BASH_REMATCH[@]}\" || printf ''"
                    return paragraphs of result
                end getMatch

                tell application "Mail"
                    set selectedMessages to selection
                    set firstSelectedMessage to first item of selectedMessages
                    set firstMessageSubject to (get subject of firstSelectedMessage)
                    set regularExpressionResult to my getMatch(firstMessageSubject, "([A-Z]+-[0-9]+)")
                    set numberOfMatches to count of regularExpressionResult

                    if numberOfMatches > 0 then
                        set ticketId to last item of regularExpressionResult
                        set ticketUrl to "https://lulububu.atlassian.net/browse/" & ticketId

                        tell application "Google Chrome"
                            activate
                            open location ticketUrl
                        end tell
                    end if
                end tell
            
        

This script just searches for something that looks like a JIRA issue key ( [A-Z]+-[0-9]+ ) and builds the full issue url. To make it work with your JIRA instance, you have to replace https://lulububu.atlassian.net/browse by your specific JIRA URL. Credits also go to this stackoverflow post from which I could recycle the getMatch function.

I bound this script on fn + f so I can easily press this keys to instantly open the JIRA issue that is related to the email I am currently reading.

Share

Comments