Open Current Forum Topic in Safari from

Hey Folks,

My generic open-list-archive script works with Discourse. It will take the selected message in and open the URL from the List-Archive mail-header (if extant) in Safari.

It also works with Yahoo Groups and any other forum that uses a List-Archive header.

All regex in this script is ‘sed’ from the shell, so no 3rd pty tools are required. All functionality can be replicated with KM except for grabbing the requisite data from Mail.

Best Regards,

Auth: Christopher Stone

dCre: 2013-04-02 : 14:00

dMod: 2013-12-15 : 10:04

Appl: Apple Mail & Default browser

Task: Visit List-Serve Page Related to List-Mail-Message if Available.

Libs: None

Osax: None

Tags: @Applescript, @Mail, @List, @Archive, @Header, @Browser

Note: Tested only on OSX 10.9.x


set listArchiveUrl to {}
set yahooGroupsBaseURL to “

tell application "Mail"
set _msg to selection
if length of _msg = 1 then
set _msg to item 1 of _msg
error "No messages OR too many messages are seleced!"
end if

tell _msg
  set listID to content of (headers whose name is "List-Id")
  if listID ≠ {} then
    set listID to item 1 of listID
  end if
  set listArchiveUrl to content of (headers whose name is "List-Archive")
  if listArchiveUrl ≠ {} then
    set listArchiveUrl to item 1 of listArchiveUrl
  end if
  if listArchiveUrl = {} then
    if listID contains "" then
      set listArchiveUrl to ""
    else if listID contains "" then
      set _cmd to "<<< " & (quoted form of listID) & " sed -E '
      set listID to do shell script _cmd
      set listArchiveUrl to yahooGroupsBaseURL & listID & "/"
    end if
  end if
end tell

end tell

if listArchiveUrl is in {{}, “”} then
set _cmd to "<<< " & (quoted form of listArchiveUrl) & " sed -E ‘s!^<|>$!!g’"
set listArchiveUrl to do shell script _cmd
tell application "Safari"
make new document with properties {URL:listArchiveUrl}
set bounds of front window to {228, 22, 1542, 1196}
end tell
end if

on error e number n
stdErr(e, n, true, true) of me
end try


on stdErr(e, n, beepFlag, ddFlag)
set e to e & return & return & "Num: " & n
if beepFlag = true then
end if
if ddFlag = true then
tell current application
set dDlg to display dialog e with title “ERROR!” buttons {“Cancel”, “Copy”, “OK”} default button "OK"
end tell
if button returned of dDlg = “Copy” then set the clipboard to e
return e
end if
end stdErr

1 Like

That seems like an awful lot of work on your part to avoid clicking on a link!