Working AppleScript for Apple Mail → Logseq links (message:// links now activate again in 0.10.15)

A few of us have run into this over the past year: message:// links pasted into Logseq stopped activating on click, even though the exact same link opens fine from Safari’s address bar (see #3186 and #11892). I can confirm this is working again as of Logseq 0.10.15 — clicking the link now correctly opens the message in Mail.

The AppleScript below builds on David Sparks’ (MacSparky) December 2025 update to his long-running Mail-link script — original post here. His update dropped the old Python dependency (Apple removed /usr/bin/python, which broke earlier versions of this script) and cleaned up the link construction. All credit for the core approach goes to him.

I extended it slightly to copy a ready-to-paste Logseq markdown link — [Subject line](message://...) — instead of the bare URL, with the subject sanitized so stray [, ], or line breaks in a mail subject can’t break the markdown:

on replaceText(theText, oldString, newString)
    set AppleScript's text item delimiters to oldString
    set theItems to every text item of theText
    set AppleScript's text item delimiters to newString
    set theText to theItems as string
    set AppleScript's text item delimiters to ""
    return theText
end replaceText

tell application "Mail"
    try
        set selMessages to selection
        if (count selMessages) > 0 then
            set msgCount to count selMessages
            if msgCount > 1 then
                display notification (msgCount as rich text) & " messages selected. Using first message." with title "Mail Link" sound name "Pop"
            end if
            set thisMsg to item 1 of selMessages
            set thisMsgID to message id of thisMsg
            set thisMsgURL to "message://%3C" & thisMsgID & "%3E"

            -- Sanitize subject so it can't break the markdown link syntax
            set safeSubject to subject of thisMsg
            set safeSubject to my replaceText(safeSubject, "]", ")")
            set safeSubject to my replaceText(safeSubject, "[", "(")
            set safeSubject to my replaceText(safeSubject, return, " ")
            set safeSubject to my replaceText(safeSubject, linefeed, " ")

            set thisMsgLink to "[" & safeSubject & "](" & thisMsgURL & ")"
            set the clipboard to thisMsgLink

            set senderText to sender of thisMsg
            if length of senderText > 30 then
                set senderText to (rich text 1 thru 30 of senderText) & "..."
            end if
            set subjectText to safeSubject
            if length of subjectText > 40 then
                set subjectText to (rich text 1 thru 40 of subjectText) & "..."
            end if
            display notification "From: " & senderText & " - " & subjectText with title "Message Link Copied" sound name "Pop"
        else
            display notification "Please select a message first." with title "No Message Selected" sound name "Basso"
        end if
    on error errMsg
        display notification errMsg with title "Error Copying Link" sound name "Basso"
    end try
end tell

Save it as a Mail script (~/Library/Application Support/Mail/Bin/ or via Script Editor + a Mail rule/service), select a message, run it, and paste — you’ll get a working, clickable link straight into a Logseq block.

Hope this saves someone else the year of frustration it caused me.

1 Like