技术积累比较深入,了解不同平台特性的朋友都会知道,Windows平台的命令行编程支持是比较弱的。相对于Linux平台脚本语言的丰饶、灵活,Windows的这方面的特性差了很多。Linux的默认Bash有很多设计缺陷和让人讨厌的地方,但即便如此,比起Windows的Bat来,还是要好上100倍了。
Win平台的bat功能实在是太弱了,它无法看作是一种语言。要干点什么复杂的事情,你得另寻它法。可能有人会问:现在是个讲究用户体验,追求设计的时代,为什么还要管这玩意儿?问这个问题的人,恐怕还都是计算机技术的菜鸟。命令行的可编程性,可以带来机械化操作类、批处理类等一切缺乏创造力活动的效率上的极大提升。
比如处理一批图片,挨个手工操作,几个还行,上千个你试试,必须用工具解决,GUI这里是碍事的。但是Windows上可选的好用的脚本语言不多。Bat太弱了,Python当然是可以的,但对于一些小活也还是麻烦了些。PowerShell?还得装套.Net,不值得,太重。这种任务,适合弱类型语言,容易“涂涂抹抹”的那种,不必考虑太多细节,容易调用外部程序,“Dirty & Quick”也无妨。
比来比去,我发现一个工具包最为适用:AutoIt.
官方介绍:https://www.autoitscript.com/site/autoit/
AutoIt
AutoIt v3 is a freeware BASIC-like scripting language designed for automating the Windows GUI and general scripting. It uses a combination of simulated keystrokes, mouse movement and window/control manipulation in order to automate tasks in a way not possible or reliable with other languages (e.g. VBScript and SendKeys). AutoIt is also very small, self-contained and will run on all versions of Windows out-of-the-box with no annoying “runtimes” required!
AutoIt was initially designed for PC “roll out” situations to reliably automate and configure thousands of PCs. Over time it has become a powerful language that supports complex expressions, user functions, loops and everything else that veteran scripters would expect.
Features:
- Easy to learn BASIC-like syntax
- Simulate keystrokes and mouse movements
- Manipulate windows and processes
- Interact with all standard windows controls
- Scripts can be compiled into standalone executables
- Create Graphical User Interfaces (GUIs)
- COM support
- Regular expressions
- Directly call external DLL and Windows API functions
- Scriptable RunAs functions
- Detailed helpfile and large community-based support forums
- Compatible with Windows XP / 2003 / Vista / 2008 / Windows 7 / 2008 R2 / Windows 8 / 2012 R2
- Unicode and x64 support
- Digitally signed for peace of mind
- Works with Windows Vista’s User Account Control (UAC)
AutoIt has been designed to be as small as possible and stand-alone with no external .dll files or registry entries required making it safe to use on Servers. Scripts can be compiled into stand-alone executables with Aut2Exe.
Also supplied is a combined COM and DLL version of AutoIt called AutoItX that allows you to add the unique features of AutoIt to your own favourite scripting or programming languages!
Best of all, AutoIt continues to be FREE – but if you want to support the time, money and effort spent on the project and web hosting then you may donate.
它首先是一门完整的语言,确确实实是可以做比较大的工作任务的,有模块化设计 – include file。另外,编写非常容易,代码很简单,调用外部程序很容易。还有,对windows接口的支持,非常的全面,几乎方方面面的常用接口都有了。实在找不到,还可以调用DLL/win32 API解决问题。
使用AutoIt编写个脚本进行批处理特别的轻松,可以用配置文件驱动,也可以命令行,一个循环就完了。它可以自己创建GUI,做成图形界面,除此之外还有一个绝技,可以自动操作键盘/鼠标,完成复杂的GUI交互操作,这些是普通的语言很难或者很麻烦才能做到的任务。你完全可以把它当成随身工具包,替代bat脚本。
此外,还有一个竞品是AutoHotKey,也是不错的。两家还有一段历史恩怨,最终两个产品各有特色。不过这里不管它了,因为我不太喜欢AutoHotKey的语法设计。有兴趣的也可以看一下。
前几天,我需要截一批视频,就是从一长段视频里面截取出很多需要的小片段来。我截取了几个就烦了,因为很麻烦。找到的几个工具,总有七七八八的问题。后来使用AutoIt做了一个脚本,很快解决问题,半小时完成了通常要1天的工作。去年,我还使用AutoIt做了一个普通方法基本无解的任务,很赞叹它的潜力。
AutoIt优质代码资源列表:https://github.com/J2TeaM/awesome-AutoIt
感谢分享。如果博主能够再深入一点详细一点做个小demo小教程的话,会帮到更多的人。
有机会做一个