微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

自动热键脚本,用于从 Doc 文件复制数据并通过应用程序或 Chrome 浏览器通过电子邮件发送

如何解决自动热键脚本,用于从 Doc 文件复制数据并通过应用程序或 Chrome 浏览器通过电子邮件发送

我在桌面上存储的 .DOC 文件中有一些文本。这可能吗

如果我按 CTRL+Q 然后,该文件中的文本将被复制 并通过 window10 中包含的任何应用程序或邮件应用程序将其通过电子邮件发送给图片显示的人。 How I want to email

***>你也可以帮我,因为我有电子邮件的网址,我只有

打开邮件地址后在那里回复并点击发送按钮。***

解决方法

获得文本形式的文件内容后,您就可以拼凑一个 mailto: URI。根据 RFC 6068 规范,解析器应接受主要电子邮件、主题和正文 - 其他字段(例如抄送地址)由解析器来实现。

这是我从找到的片段中拼凑而成的快速脚本。

#SingleInstance Force

EmailRecipient := "target@example.com"
EmailCC := ["target2@example.com","target3@example.com"]
EmailSubject := "MY WORK PROGRESS"

^Q::
; Step 1) Gets filepath of first file
FirstFilePath := getFirstSelected()

; Step 2) Makes sure its a DOC or DOCX file
if (!(SubStr(FirstFilePath,-3) = ".doc" || SubStr(FirstFilePath,-4) = ".docx")) {
  MsgBox 0x1010,Doc Mailer,% "Not a doc/docx file!"
  return
}

; Learning one
; https://autohotkey.com/board/topic/73386-fileread-word-docx-com-l-line-40-error/?p=494436
; Step 3) Opens it as a COM Object and copies its text content to the clipboard
oDoc := ComObjGet(FirstFilePath)
oDoc.Range.FormattedText.Copy  ; OR oDoc.Range.Text.Copy
oDoc.Close(0)

; Step 4) Takes the content on the clipboard and URI encodes it
encodedBody:=UriEncode(clipboard)

; Step 5) Build GET query string parts
params := []
if (EmailCC && EmailCC.Length()) {
  params.Push("cc=" . UriEncode(StrJoin(EmailCC,",")))
}
if (EmailSubject) {
  params.Push("subject=" . UriEncode(EmailSubject))
}
if (encodedBody) {
  params.Push("body=" . encodedBody)
}
paramsStr := StrJoin(params,"&")

; Step 6) Build the mailto: URI
;MsgBox % "mailto:" . EmailRecipient . (paramsStr ? "?" . paramsStr : "")
Run,% "mailto:" . EmailRecipient . (paramsStr ? "?" . paramsStr : "")

return

; ---------------------

; Modified from Masonjar13's function
; https://www.autohotkey.com/boards/viewtopic.php?p=154791#p154791
getFirstSelected(){
    cO:=clipboardAll
    clipboard:=
    send ^c
    clipWait
    selected:=clipboard
    clipboard:=cO
    return StrSplit(selected,"`r`n")[1]
}

; ---------------------

; https://autohotkey.com/board/topic/75390-ahk-l-unicode-uri-encode-url-encode-function/?p=480216
; modified from jackieku's code (http://www.autohotkey.com/forum/post-310959.html#310959)
UriEncode(Uri,Enc = "UTF-8")
{
    StrPutVar(Uri,Var,Enc)
    f := A_FormatInteger
    SetFormat,IntegerFast,H
    Loop
    {
        Code := NumGet(Var,A_Index - 1,"UChar")
        If (!Code)
            Break
        If (Code >= 0x30 && Code <= 0x39 ; 0-9
            || Code >= 0x41 && Code <= 0x5A ; A-Z
            || Code >= 0x61 && Code <= 0x7A) ; a-z
            Res .= Chr(Code)
        Else
            Res .= "%" . SubStr(Code + 0x100,-1)
    }
    SetFormat,%f%
    Return,Res
}

UriDecode(Uri,Enc = "UTF-8")
{
    Pos := 1
    Loop
    {
        Pos := RegExMatch(Uri,"i)(?:%[\da-f]{2})+",Code,Pos++)
        If (Pos = 0)
            Break
        VarSetCapacity(Var,StrLen(Code) // 3,0)
        StringTrimLeft,1
        Loop,Parse,`%
            NumPut("0x" . A_LoopField,"UChar")
        StringReplace,Uri,`%%Code%,% StrGet(&Var,Enc),All
    }
    Return,Uri
}

StrPutVar(Str,ByRef Var,Enc = "")
{
    Len := StrPut(Str,Enc) * (Enc = "UTF-16" || Enc = "CP1200" ? 2 : 1)
    VarSetCapacity(Var,Len,0)
    Return,StrPut(Str,&Var,Enc)
}

; ---------------------

StrJoin(arr,delim = ",") {
  ret := ""
  Loop % arr.Length()
    ret := ret . (A_Index = 1 ? "" : delim) . arr[A_Index]
  return ret
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。