Open Current Forum Topic in Safari from Mail.app

Hey Folks,

My generic open-list-archive script works with Discourse. It will take the selected message in Mail.app 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,
Chris

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


try

set listArchiveUrl to {}
set yahooGroupsBaseURL to “http://groups.yahoo.com/neo/groups/

tell application "Mail"
set _msg to selection
if length of _msg = 1 then
set _msg to item 1 of _msg
else
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 "applescript-users.lists.apple.com" then
      set listArchiveUrl to "http://lists.apple.com/archives/applescript-users"
      
    else if listID contains "yahoogroups.com" then
      set _cmd to "<<< " & (quoted form of listID) & " sed -E '
        s![<>]!!g
        s!\\.yahoogroups\\.com$!!
      '"
      
      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
beep
return
else
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}
activate
end tell
end if

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


–» HANDLERS

on stdErr(e, n, beepFlag, ddFlag)
set e to e & return & return & "Num: " & n
if beepFlag = true then
beep
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
else
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!

Thanks,

Roy