• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Email to Script Debugger or Script Editor
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Email to Script Debugger or Script Editor


  • Subject: Email to Script Debugger or Script Editor
  • From: Christopher Stone <email@hidden>
  • Date: Thu, 19 Nov 2015 08:49:31 -0600

Hey Folks,

I wrote a script to send the text of the selected message in Mail to Script Debugger.

It filters-out some stuff using the Satimage.osax.

Switching-out the Script Debugger code for Script Editor is easy enough:

-------------------------------------------------------------------------------------------
tell application "Script Editor"
  activate
  set newDoc to make new document with properties {text:content_}
  set bounds of newDoc's window to {606, 23, 1920, 1196}
end tell
-------------------------------------------------------------------------------------------

At some point when I have abundant time I'll probably add some code that attempts to comment-out the remaining non-script portions.

I wanted to port this to ASObjC, so even those who won't install the Satimage.osax would have a new toy – but writing handlers in ASObjC to fully replace the SIO's find text and change commands has proven rather difficult.  Half-ass'ing them wouldn't be too hard, but I'd rather not.

I'd rather set this loose in the meantime for anyone who can get some use out of it.

--
Best Regards,
Chris

-------------------------------------------------------------------------------------------
# Auth: Christopher Stone <email@hidden>
# dCre: 2014/07/31 12:04
# dMod: 2015/10/24 03:34
# Appl: Mail & Script Debugger
# Task: Send Message Content to Script Debugger
# Osax: Satimage.osax { http://tinyurl.com/dc3soh } REQUIRED!
# Tags: @Applescript, @Script, @Mail, @Filtered, @Message, @Text, @Script_Debugger
-------------------------------------------------------------------------------------------

try

  

  set _sep to "-------------------------------------------------------------------------------------------"

  

  tell application "Mail"
    set selMsgList to selection
    if selMsgList ≠ {} then
      set selMsg to item 1 of selMsgList
      tell selMsg
        set headers_ to all headers
        set content_ to content
        set listID to headers whose name is "List-Id"
        if length of listID = 1 then
          set listID to content of item 1 of listID
        end if
      end tell
    end if
  end tell

  

  set from_ to fnd("^From:.*", headers_, 0, 1) of me
  set subject_ to fnd("^Subject:.*", headers_, 0, 1) of me
  set date_ to fnd("^Date:.*", headers_, 0, 1) of me
  set to_ to fnd("^To:.*", headers_, 0, 1) of me

  

  if fndBool("^Reply-To:.*", headers_, 0, 1) of me ≠ false then
    set replyTo to result
  else
    set replyTo to ""
  end if

  

  if fndBool("^X-Sender:.*", headers_, 0, 1) of me ≠ false then
    set xSender to result
  else
    set xSender to ""
  end if

  

  set smallHeaders to join {subject_, from_, date_, replyTo, to_, xSender} using linefeed
  set smallHeaders to cng("^[[:blank:]]*$[\\n\\r]?", "", smallHeaders) of me
  set smallHeaders to cng("^([^:]+:) ", "\\1\\t", smallHeaders) of me
  set smallHeaders to do shell script "column -t -s'" & tab & "' <<< " & quoted form of smallHeaders without altering line endings
  set smallHeaders to cng("^([^:]+)(:)([[:blank:]]+)", "\\1\\3\\2  ", smallHeaders) of me
  set smallHeaders to stripWhiteSpaceTopBottom(smallHeaders)
  set smallHeaders to cng("^", "# ", smallHeaders) of me

  

  # NBS (non-breaking space) to space:
  set content_ to cng("[\\x{FFFC}\\x{A0}]", " ", content_) of me
  set content_ to cng("\\n{3,}", "\\n", content_) of me
  set content_ to cng("\\r]{3,}", "\\r", content_) of me

  

  if listID contains "applescript-users.lists.apple.com" then
    set content_ to rmvAsulJunk(content_)
  else if listID contains "bbedit.googlegroups.com" then
    set content_ to rmvBBeditTalkJunk(content_)
  end if

  

  set content_ to _sep & linefeed & smallHeaders & linefeed & _sep & linefeed & linefeed & stripWhiteSpaceTopBottom(content_)

  

  tell application "Script Debugger"
    activate
    set newDoc to make new document with properties {source text:content_}
    set bounds of newDoc's window to {606, 23, 1920, 1196}
  end tell

  

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

-------------------------------------------------------------------------------------------

--» HANDLERS

-------------------------------------------------------------------------------------------
--» FILTER HANDLERS
-------------------------------------------------------------------------------------------
on rmvAsulJunk(textData)
  set textData to cng("(?m)_______________________________________________\\n+Do not post admin.+?\\nApplescript-Users mailing list.+This email sent to email@hidden", "", textData) of me
end rmvAsulJunk
-------------------------------------------------------------------------------------------
on rmvBBeditTalkJunk(textData)
  set textData to cng("(?m)--\\s*This is the BBEdit Talk public discussion group. If you have a.+To post to this group, send email to email@hidden.", "", textData) of me
end rmvBBeditTalkJunk
-------------------------------------------------------------------------------------------
on stripWhiteSpaceTopBottom(textData)
  set textData to cng("\\A\\s+|\\s+\\Z", "", textData) of me
end stripWhiteSpaceTopBottom

-------------------------------------------------------------------------------------------
--» SATIMAGE.OSAX HANDLERS
-------------------------------------------------------------------------------------------
on cng(_find, _replace, _data)
  change _find into _replace in _data with regexp without case sensitive
end cng
-------------------------------------------------------------------------------------------
on fnd(_find, _data, _all, strRslt)
  try
    find text _find in _data all occurrences _all string result strRslt with regexp without case sensitive
  on error
    return false
  end try
end fnd
-------------------------------------------------------------------------------------------
on fndBool(_find, _data, _all, strRslt)
  try
    find text _find in _data all occurrences _all string result strRslt with regexp without case sensitive
    return true
  on error
    return false
  end try
end fndBool

-------------------------------------------------------------------------------------------
--» ERROR HANDLER
-------------------------------------------------------------------------------------------
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 me
      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
-------------------------------------------------------------------------------------------



 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

  • Follow-Ups:
    • Re: Email to Script Debugger or Script Editor
      • From: Shane Stanley <email@hidden>
    • Re: Email to Script Debugger or Script Editor
      • From: Yvan KOENIG <email@hidden>
  • Prev by Date: Re: applescripting sub mailboxes in Mail
  • Next by Date: Re: Email to Script Debugger or Script Editor
  • Previous by thread: Re: POSIX vs Macinotosh Path Strings
  • Next by thread: Re: Email to Script Debugger or Script Editor
  • Index(es):
    • Date
    • Thread