0
点赞
收藏
分享

微信扫一扫

[AHK]修正文件名乱码


问题:下载的文件 名字含有乱码

解决:ahk调用js函数辅助改成正确的文件名,详见下面动图演示。

 

[AHK]修正文件名乱码_热键

热键:Ctrl+F2

;脚本功能:搞定乱码文件名,选中待修正名字的文件,按Ctrl+F2即可

;举例:
;乱码文件名:DevOps%E7%9A%84%E6%A6%82%E5%BF%B5%E4%B8%8E%E5%AE%9E%E8%B7%B5_2014.pdf
;改后文件名:DevOps的概念与实践_2014.pdf
;作者:sunwind
;时间:2019年1月12日11:40:03


#SingleInstance,force
;热键:Ctrl+F2
^F2::
hwnd := WinExist("A")
For window in ComObjCreate("Shell.Application").Windows
	doc :=   window.Document
Until   (window.hWnd = hWnd)
For item in doc.SelectedItems {
	if (a_index=1)
	{
		filename:=item.name
	}
   ;多个文件,暂不支持
   ;~ sSelect .=   (!sSelect ? "" : "`n") item.path
  }

Send {F2}
;选中扩展名
Send ^a
;输入法状态设置为英文,以避免影响
IME_SET(0)  
SendInput % uridecode(filename)
Send {Enter}
return


;*********************
;辅助函数
;*********************
UriDecode(Uri)
{
    oSC := ComObjCreate("ScriptControl")
    oSC.Language := "JScript"
    Script := "var Decoded = decodeURIComponent(""" . Uri . """)"
    oSC.ExecuteStatement(Script)
    Return, oSC.Eval("Decoded")
}
IME_SET(setSts, WinTitle="")
;-----------------------------------------------------------
; IMEの状態をセット
;    対象: AHK v1.0.34以降
;   SetSts  : 1:ON 0:OFF
;   WinTitle: 対象Window (省略時:アクティブウィンドウ)
;   戻り値  1:ON 0:OFF
;-----------------------------------------------------------
{
    ifEqual WinTitle,,  SetEnv,WinTitle,A
    WinGet,hWnd,ID,%WinTitle%
    DefaultIMEWnd := DllCall("imm32\ImmGetDefaultIMEWnd", Uint,hWnd, Uint)
    ;Message : WM_IME_CONTROL  wParam:IMC_SETOPENSTATUS
    DetectSave := A_DetectHiddenWindows
    DetectHiddenWindows,ON
    SendMessage 0x283, 0x006,setSts,,ahk_id %DefaultIMEWnd%
    DetectHiddenWindows,%DetectSave%
    Return ErrorLevel
}

 

举报

相关推荐

0 条评论