网站首页 > 技术教程 正文
最近用autohotkey解决了一个需要重复几百次的工作任务,类似枯燥的的任务都可以用autohotkey来解决掉!
任务如下:
根据mp3文件名称,生成一个相同文件名称的文本文件和一个带有-1的文本文件,比如当我选中过零丁洋.mp3的时候,按下ctrl+win+t,就会生成下面这样的两个 txt文件。一开始我用笨办法,复制mp3文件名,再新建两个文本文件,把文件名粘贴过去,修改其中一个为-1, 全部弄完需要10多秒,有时候还容易出错,写成脚本就节省了自己大量的时间,正所谓磨刀不误砍柴工!
官网中文文档
autohotkey是一个制作按键脚本的工具,免费且强大!
https://www.autoahk.com/help/autohotkey/zh-cn/docs/AutoHotkey.htm
代码实战
^#t::
txtFileName := Explorer_GetSelection(hwnd)
txtFileName := RegExReplace(txtFileName, ".mp3#34;, "")
MsgBox % "准备写入" txtFileName
file := FileOpen(txtFileName "-1.txt", "w")
file.Write(txtFileName ".txt")
file.Close()
file := FileOpen(txtFileName ".txt", "w")
file.Write(txtFileName ".txt")
file.Close()
return
Explorer_GetSelection(hwnd="")
{
WinGet, process, processName, % "ahk_id" hwnd := hwnd? hwnd:WinExist("A")
WinGetClass class, ahk_id %hwnd%
if (process != "explorer.exe")
return
if (class ~= "Progman|WorkerW") {
ControlGet, files, List, Selected Col1, SysListView321, ahk_class %class%
Loop, Parse, files, `n, `r
ToReturn .= A_Desktop "\" A_LoopField "`n"
} else if (class ~= "(Cabinet|Explore)WClass") {
for window in ComObjCreate("Shell.Application").Windows
{
try{
if (window.hwnd==hwnd)
sel := window.Document.SelectedItems
}catch e {
continue
}
}
for item in sel
ToReturn .= item.path "`n"
}
return Trim(ToReturn,"`n")
}
解释下:
触发快捷键
^#t::
表示的就是当你按下ctrl+win+t的时候干什么。
符号描述:
符号 | 描述 |
# | Win(Windows 徽标键) |
! | Alt |
^ | Ctrl |
+ | Shift |
& | 用于连接两个按键(含鼠标按键) 合并成一个自定义热键. |
赋值
txtFileName := Explorer_GetSelection(hwnd)
从函数Explorer_GetSelection中获取到选中文件名称后,新建txtFileName变量并赋值。
正则替换
替换.mp3为空
RegExReplace(txtFileName, ".mp3#34;, "")
显示对话框
MsgBox % "准备写入" txtFileName
%是把后面的参数变成表达式,不加的话会出错。
字符串合并
非常简单,与其它编程语言不同的是,并不需要+号
"txtFileName: " txtFileName
相当于js中的"txtFileName: " + txtFileName
新建文件
file := FileOpen(txtFileName "-1.txt", "w")
file.Write(txtFileName ".txt")
file.Close()
- txtFileName "-1.txt"是目标文件名称,"w"表示写入模式打开文件
- file.write是写入文件内容,本例中是写入
- 记得最后使用file.Close()关闭文件
获取选中文件名称
直接拿过去用:
Explorer_GetSelection(hwnd="")
{
WinGet, process, processName, % "ahk_id" hwnd := hwnd? hwnd:WinExist("A")
WinGetClass class, ahk_id %hwnd%
if (process != "explorer.exe")
return
if (class ~= "Progman|WorkerW") {
ControlGet, files, List, Selected Col1, SysListView321, ahk_class %class%
Loop, Parse, files, `n, `r
ToReturn .= A_Desktop "\" A_LoopField "`n"
} else if (class ~= "(Cabinet|Explore)WClass") {
for window in ComObjCreate("Shell.Application").Windows
{
try{
if (window.hwnd==hwnd)
sel := window.Document.SelectedItems
}catch e {
continue
}
}
for item in sel
ToReturn .= item.path "`n"
}
return Trim(ToReturn,"`n")
}
呼,节省的时间可以多陪陪家人了。
猜你喜欢
- 2024-11-09 AutoHotkey V2.0.12 中文Help文档已完成!
- 2024-11-09 让你在 Windows 上打字摆脱鼠标,试试用这套方案快速移动光标
- 2024-11-09 效率倍增器来了!终极快捷键该这么用
- 2024-11-09 魔兽世界怀旧服:高科技玩法电脑代替人脑,只需一键打出完美DPS
- 2024-11-09 打榜全靠脚本宏?暴雪定义AHK为外挂,竞速团一个都走不掉
- 2024-11-09 远程办公,我们建议用这个软件,顺畅到PS都能用
- 2024-11-09 在电脑上怎么在每天的某个时刻自动打开指定文件?6种方法教给你
- 2024-11-09 Redis数据倾斜与JD开源hotkey源码分析揭秘
- 2024-11-09 系统小技巧:Windows 10执行任务快上加快
- 2024-11-09 在Windows 11操作系统中,热键(快捷键
你 发表评论:
欢迎- 最近发表
-
- Win11学院:如何在Windows 11上使用WSL安装Ubuntu
- linux移植(Linux移植freemodbus)
- 独家解读:Win10预览版9879为何无法识别硬盘
- 基于Linux系统的本地Yum源搭建与配置(ISO方式、RPM方式)
- Docker镜像瘦身(docker 减小镜像大小)
- 在linux上安装ollama(linux安装locale)
- 渗透测试系统Kali推出Docker镜像(kali linux渗透测试技术详解pdf)
- Linux环境中部署Harbor私有镜像仓库
- linux之间传文件命令之Rsync傻瓜式教程
- 解决ollama在linux中安装或升级时,通过国内镜像缩短安装时长
- 标签列表
-
- 下划线是什么 (87)
- 精美网站 (58)
- qq登录界面 (90)
- nginx 命令 (82)
- nginx .http (73)
- nginx lua (70)
- nginx 重定向 (68)
- Nginx超时 (65)
- nginx 监控 (57)
- odbc (59)
- rar密码破解工具 (62)
- annotation (71)
- 红黑树 (57)
- 智力题 (62)
- php空间申请 (61)
- 按键精灵 注册码 (69)
- 软件测试报告 (59)
- ntcreatefile (64)
- 闪动文字 (56)
- guid (66)
- abap (63)
- mpeg 2 (65)
- column (63)
- dreamweaver教程 (57)
- excel行列转换 (56)
本文暂时没有评论,来添加一个吧(●'◡'●)