9
votes

We all have tasks that come up from time to time that we think we'd be better off scripting or automating than doing manually.

Obviously some tools or languages are better for this than others - no-one (in their right mind) is doing a one off job of cross referencing a bunch of text lists their PM has just given them in assembler for instance.

What one tool or language would you recommend for the sort of general quick and dirty jobs you get asked to do where time (rather than elegance) is of the essence?

Background: I'm a former programmer, now development manager PM, looking to learn a new language for fun. If I'm going to learn something for fun I'd like it to be useful and this sort of use case is the most likely to come up.

4
  • This is a third party software winautomation.com
    – PradeepGB
    Nov 16, 2010 at 10:50
  • 3
    As you can tell by the variety of answers below, the best solution depends on exactly what you want to accomplish and in what environment.
    – Mark C
    Nov 16, 2010 at 14:29
  • @Mark - I appreciate that but I'm ideally looking to learn one thing which has as generic an application as possible. Nov 17, 2010 at 12:17
  • If you want to do everything, I suppose you will need at least 2-3 programs. Linux, Windows, MacOS? Code, filesystem, application macros?
    – Mark C
    Nov 19, 2010 at 0:57

13 Answers 13

25
votes

Python

The obvious answer (and with good reason) is Python. Its a solid language, available cross platform. As its dynamic you can run it interactively which is great for lashing stuff together and it has a fairly large selection of libraries so its a general purpose language so can be applied to most problems.

10
  • That's the beauty. Thinking of "scripting" and "programming" languages as totally different animals is pretty much obsolete when there's Python. Nov 16, 2010 at 11:25
  • Ish, one of the key things in powershell is the pipelining - not sure how feasible that is in python (generically at least)
    – Murph
    Nov 16, 2010 at 12:17
  • +1, Python gets my vote as the best all around multi purpose scripting language.
    – Josh K
    Nov 16, 2010 at 12:51
  • +1 Same here, python works on most if not all platforms and is really the better "scripting" language for hacking some code together. Nov 16, 2010 at 13:30
  • 1
    xkcd.com/353
    – Will
    Dec 31, 2010 at 15:36
12
votes

Autoit is unbeatable. It's a tool with a language.

  • 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 2000 / XP / 2003 / Vista / 2008 / Windows 7 / 2008 R2
  • Unicode and x64 support
  • Digitally signed for peace of mind
  • Works with Windows Vista's User Account Control (UAC)
8
votes

AutoHotKey

AutoHotkey is a free, open-source utility for Windows. With it, you can:

  1. Very friendly and helpful community.
  2. C like syntax.
  3. Automate almost anything by sending keystrokes and mouse clicks.
  4. You can write a mouse or keyboard macro by hand or use the macro recorder.
  5. Create hotkeys for keyboard, joystick, and mouse. Virtually any key, button, or combination can become a hotkey.
  6. Manipulate windows and processes.
  7. Interact with all standard windows controls.
  8. Expand abbreviations as you type them. For example, typing "btw" can automatically produce "by the way".
  9. Create custom data-entry forms, user interfaces, and menu bars. See GUI for details.
  10. Remap keys and buttons on your keyboard, joystick, and mouse.
  11. Create Graphical User Interfaces (GUIs).
  12. COM support.
  13. Regular expressions.
  14. Directly call external DLL and Windows API functions.
  15. Unicode, x32 and x64 support.
  16. Respond to signals from hand-held remote controls via the WinLIRC client script.
  17. Convert any script into an EXE file that can be run on computers that don't have AutoHotkey installed.

http://ahkscript.org/

I've saved several companies a large sum of money by using this tool.

6
votes

Powershell

This is less generic than Python - but if you exist in a Windows environment then its probably that its going to be more useful.

Its more shell/script like than Python (because that's what it is) but it can hook into the .NET framework which gives you a quite extraordinary depth of capability. It also has broad community support.

Microsoft have been busy adding powershell to their server products (hence the "more useful") and have introduced remoting to allow you to run scripts there from your console here.

1
  • 5
    Could the bright spark who downvoted without commenting please explain themselves? Thanks.
    – Murph
    Nov 16, 2010 at 14:09
6
votes

Perl

Perl is pretty much my definition of quick and dirty.

Perl is infinitely flexible which is a strength and weakness. It doesn't force structure on you, but it's there if you want it. It has libraries for everything. It's been used extensively for 20 years; there's tons of code out there to work with.

4
  • 3
    I thought Perl would come up a lot sooner. I'd considered Perl as I've got passing exposure to it but it just makes me want to scrub my eyes with bleach every time I read it. $=;$_=\%!; $_)=/(.)/;$==++$|;($.,$/,$,,$\,$",$;,$^,$#,$~,$*,$:,@%)=($!=~/(.)(.).(.)(.)(.)(.)..(.)(.)(.)..(.).......)/,$"),$=++;$.++;$.++;$_++;$_++;($_,$\,$,)=($~.$"."$;$/$%[$?]$_$\$,$:$%[$?]",$"&$~,$#,);$,++;$,++;$^|=$";$_$\$,$/$:$;$~$*$%[$?]$.$~$*${#}$%[$?]$;$\$"$^$~$*.>&$= (that's actual Perl - admittedly wilfully bad Perl - for those who don't read it). Nov 16, 2010 at 16:26
  • 1
    @Jon I mostly added it because it wasn't here. I agree it can get pretty messy, it doesn't enforce any discipline on you, you have to bring your own. Considering the vast majority of the time it's used for quick and dirty scripting, you get what you see. Nov 16, 2010 at 16:29
  • 2
    Yep - and Perl shouldn't be blamed for the messiness, that's down to the programmer. Besides, if your programming language only lets you write good code, you get no credit for doing so... Nov 16, 2010 at 16:30
  • 1
    I think Perl is the best scripting language now extant - it's not opinionated and lets do what you need to do without griping. Nov 16, 2010 at 16:32
5
votes

A modern unix shell. E.g. bash.

1
  • Assuming of course that you're running in an enviroment that natively supports it (or that you count powershell as equivalent to a modern unix shell (-:)
    – Murph
    Nov 16, 2010 at 16:41
3
votes

elisp, if you have seen the wealth of tasks it is used in order to accomplish through its underlying platform Emacs. Emacs can eschew all the functionality of a full blown window manager, IDE, Office, browser, email client, chat client, shell, filesystem explorer, and more. Most of it is accomplished through elisp programs.

1
vote

For some tasks, Actions might be a good fit.

It has a sort-of flowcharting process, where you can add actions to be run sequentially. New actions can be written in java.

Disclaimer: I've yet to use it.

1
vote

For complex automation you may want to use Robot Framework. The framework is mostly aimed at automated testing but can also be used for general automation.

You can easily write your own libraries in Python and there are a number of pre-existing ones (selenium, AutoIt, telnet, ssh, swing, etc) which allow you to drive all sorts of things which is very powerful if you're in a mixed enviroment.

It is keyword driven so you can create new keywords and hence abstract away repetitive tasks and even has an IDE which is being actively developed that allows for some simple refactorings.

1
vote
  • The GUI guys in my organization like TestComplete for automation in Windows.
  • For CLI scripting, about 90% Perl and 10% Bash

I've been working on rolling together some Common Lisp routines to help with scripting, but it's not as easily native to that task as Perl.

0
votes

For windows I highly recommend AutoIt (http://autoitscript.com). Make sure to install the Scite package from the downloads section.

http://autoitscript.com/forum is a great resource for getting help and finding UDF's function to include in scripts.

AutoIt is able to control application windows and controls allowing you automate just about anything. It also requires no dependencies after you compile you executable.

0
votes

I had the same problem of using multiple languages for different set of automation. I'm a senior consultant for an IT Service company in India. Every time I consult a different

language for the purpose, I had tough time justifying it to the management. I even discussed with my friends (as casual talk) about developing a unified language that address all the automation needs and still cross-platform. If one is available, then it may

change the scripting world. As far as I know, the mapping we usually use goes

Languages and usage domain

AutoIT - Windows based GUI Automation Bash - Unix based automation mostly involves system interaction Perl - Data processing automation with less system interaction Expect - Character based interactive requirements. (which cannot be solved by Perl, Bash) VBS - Windows based scripting

Any Automation always accompanies with one or more remote invocation for either information retrieval or result publishing. Here are the different list addressing major OS.

Remote Script Invocation (tools)

Windows -> Windows

psexec, Powershell

Windows -> Unix

plink, Quest Plink -> SSH Server

Unix -> Unix

SSH client -> SSH Server

Unix -> Windows

winexe, wmic -> WMI Agent check_nrpe -> NRPE_NT Agent

In the above list, you can easily make out that no language can replace another in feature set. We've to live with those until we have one universal OS and universal standard of communication protocols and APIs.

-2
votes

Python is great for this and has a larger install base, and Ruby is not any better except it has Why's Poignant Guide to Ruby. Seriously, cartoon foxes.

Not the answer you're looking for? Browse other questions tagged or ask your own question.