Expanding Python as a macro language

Q

qwweeeit

Hi all,
when I moved from Windows to Linux I choosed Python as my language of
reference and as GUI, Qt (not much investigated up to now).
Till now I didn't regret but one thing:
Python can't act as a macro language and so you are obliged to revert
to Windows to use programs like AutoIt, Macro Express or Macro
Scheduler or even the macro features of Office with VBA.

Claudio Grondi expressed almost the same ideas in answering to a post:
> What I can point you to is not Python, but embedding it in Python
> is a question of executing one line of Python code triggering its
> execution.
> I think you will be fascinated by its features and ease of use
> and how well it is suited to fit into your needs:
> http://www.autoitscript.com/autoit3/index.php
> With it you will start to see, that forcing to obey to Windows way
> of doing things has not only bad sides.

In answering to him I expressed the idea to use Windows and AutoIt 3
for automation purposes.
But then I changed idea... Also if it is already one year that I try
to find a solution in Linux (mainly with Python or DCOP and KDE),
I am still confident that there is a solution (in Python we have big
experts...).
Instead of merely "batteries included" we have plenty of already made
applications (from graphics to browsing or editing etc.) that can be
easily accessed emulating users operations (mainly keystrokes or mouse
operations)...
Bye.
 
S

SPE - Stani's Python Editor

Well on Windows I used some time ago for similar tasks the wmi module.
It is able to analyse running programs, press buttons and activate menu
items. As you didn't mention it, you might have a look at it. It works
pretty well.

http://tgolden.sc.sabren.com/python/wmi.html

For linux I don't know.
 
D

Do Re Mi chel La Si Do

Hi !


Not the good answer, but, for information :

AutoIt is very better in beta-release (many versions beta exist). AutoIt
beta can use COM call, and can use COM-server writed in Python with win32all
(PyWin).

And, also, AutoIt exist like Active-X (in reality a COM server), who can to
do used from Python (+ PyWin).


@-salutations

Michel Claveau
 
Q

qwweeeit

Thank you for your replays (both for WMI and AutoIt beta-release)
but I would be satisfied if I had in Linux something similar to
the standard version of AutoIt!
Concerning WMI, a part the fact that it works only under Windows,
from the examples I have seen, IMHO it is much less powerful than
AutoIt.
In Linux you can easily obtain almost the same results by using shell
programming or by emulation of the shell by means of os.system("shell
command string") in Python.
But the problem is that in Linux you can't even send a keystroke to
a running GUI application!
I want to find a solution in Linux, with the help of experts
(if they don't use only Windows...) for two reasons:
- the reduced availability in Windows of "free" or "open" applications
- the more severe security problems in Windows.
Concerning the second point, you can correctly argue that this is,
at least partly, due to the wider market share of Windows but IMHO
Linux is more robust in this field, and ...at the present times the
situation is like that!
As I want to use automation mainly in Internet, I am worried of
security and I don't want to spend time and money in anti-virus
and firewalls...
I want to give you an idea of possible applications of automation.
Imagine you want to access a big database from a html server which
only allows you to access such data in chunks pressing a "next"
button on an ASP file. It will take several hours to click the button
and then save the new data supplied by the server!
That is a typical task of AutoIt, very easily programmable,
a part that, during the script execution, you are under virus or
other security treat!
Another example of application is to emulate a spider program to make
searches or downloads in Internet. By emulating a user you can bypass
the restrictions imposed by search engines or html servers on
automatic operations (like wget or urlib).
A last example is for protecting the privacy using several
"anonymizers". That can only be possible with a macro language for
automatic connection to the web anonymizers. Also the subsequent
web operations must be carried out (IMHO!) in an automatic manner.
There are of course plenty of possible application of a macro language
and above all it can save me from be obliged to learn C++ (for Qt).
For example, to make a graph you are not obliged to make a program in
C++ or PyQt to draw and possibly print the graph of your data, but you
need only to program the data preparation then send the data to a
drawing application...
Bye.
 
Q

qwweeeit

Thank you for your replays (both for WMI and AutoIt beta-release)
but I would be satisfied if I had in Linux something similar to
the standard version of AutoIt!
Concerning WMI, a part the fact that it works only under Windows,
from the examples I have seen, IMHO it is much less powerful than
AutoIt.
In Linux you can easily obtain almost the same results by using shell
programming or by emulation of the shell by means of os.system("shell
command string") in Python.
But the problem is that in Linux you can't even send a keystroke to
a running GUI application!
I want to find a solution in Linux, with the help of experts
(if they don't use only Windows...) for two reasons:
- the reduced availability in Windows of "free" or "open" applications
- the more severe security problems in Windows.
Concerning the second point, you can correctly argue that this is,
at least partly, due to the wider market share of Windows but IMHO
Linux is more robust in this field, and ...at the present times the
situation is like that!
As I want to use automation mainly in Internet, I am worried of
security and I don't want to spend time and money in anti-virus
and firewalls...
I want to give you an idea of possible applications of automation.
Imagine you want to access a big database from a html server which
only allows you to access such data in chunks pressing a "next"
button on an ASP file. It will take several hours to click the button
and then save the new data supplied by the server!
That is a typical task of AutoIt, very easily programmable,
a part that, during the script execution, you are under virus or
other security treat!
Another example of application is to emulate a spider program to make
searches or downloads in Internet. By emulating a user you can bypass
the restrictions imposed by search engines or html servers on
automatic operations (like wget or urlib).
A last example is for protecting the privacy using several
"anonymizers". That can only be possible with a macro language for
automatic connection to the web anonymizers. Also the subsequent
web operations must be carried out (IMHO!) in an automatic manner.
There are of course plenty of possible application of a macro language
and above all it can save me from be obliged to learn C++ (for Qt).
For example, to make a graph you are not obliged to make a program in
C++ or PyQt to draw and possibly print the graph of your data, but you
need only to program the data preparation then send the data to a
drawing application...
Bye.
 
M

Michael

But then I changed idea... Also if it is already one year that I try
to find a solution in Linux (mainly with Python or DCOP and KDE),

This doesn't express the question you have anywhere clearly enough. Linux
can run perfectly happily without any form of windowing environment. Many
people run using Gnome. Many others using KDE. And the number of people who
use *neither* of those but some window manager is still high.

Do you want to replay against qt applications? KDE? wx? GTK? Or send raw X11
events? The answers to these questions aren't linux specific either...


Michael.
 
A

Alex Martelli

But the problem is that in Linux you can't even send a keystroke to
a running GUI application!

Actually, if the app is running under X11 you may try to fake out a
keystroke event (with low level calls, but ctypes might let you use it
from Python). Of course, the app WILL be told that the keystroke is
fake, through a special flag if it cares to check for it, for security
reasons; but if the app doesn't specifically defend itself in this way.

See, for example, http://xmacro.sourceforge.net/ -- I guess that
xmacroplay could pretty easily be adapted, or maybe even used as is with
an os.popen.

I want to find a solution in Linux, with the help of experts
(if they don't use only Windows...) for two reasons:
- the reduced availability in Windows of "free" or "open" applications
- the more severe security problems in Windows.
Concerning the second point, you can correctly argue that this is,
at least partly, due to the wider market share of Windows but IMHO
Linux is more robust in this field, and ...at the present times the
situation is like that!

Don't neglect MacOSX -- it's quite secure, there are many open and free
applications, AND it has a decent architecture for the kind of tasks you
want to do (mostly intended for Apple's own Applescript language, but
all the interfaces are open and easily available to Python, which is
quite well supported on the Mac).

It also has an excellent italian newsgroup, it.comp.macintosh -- quite
high volume (as it discusses ANYthing Apple, from iPod shuffles to
golden oldies to rumors about new servers &c, with a lot of volume on
the audio and video applications that macs do so well) but worth it.


However, all the specific use cases you describe are best handled by
either fully emulating or directly integrating with a browser; faking
keystrokes is definitely too low-level an approach. Python is very good
at dealing with the web (it IS, apparently, the favourite language of
Tim Berners Lee --- he came give a keynote at a Python conference),
including recording and replaying cookies and anything else you may need
to make a "special purpose browser" for automation purposes. Twisted is
an asynchronous framework for very well-performing, lightweight clients
and servers -- or, Python's standard library can suffice if you're not
in a terrible hurry;-).

Alternatively, Firefox and other Mozilla Foundation apps are designed to
be automated via XPCOM, essentially a cross-platform equivalent of
Microsoft's good old COM, and there are Python interfaces to it (some
future Firefox version might perhaps integrate a Python engine, just
like it integrates a Javascript engine today, but I wouldn't hold my
breath waiting;-).


Alex
 
M

Mike Meyer

...
Actually, if the app is running under X11 you may try to fake out a
keystroke event (with low level calls, but ctypes might let you use it
from Python). Of course, the app WILL be told that the keystroke is
fake, through a special flag if it cares to check for it, for security
reasons; but if the app doesn't specifically defend itself in this way.

I'm pretty sure that python-xlib can do this without having to go to
low level calls.

<mike
 
Q

qwweeeit

At first you must forgive my double posting (4 & 5 in terms of date and
4 & 7 in terms of answers). I must then thank the new comers:
Michael, Alex Martelli and Mike Meyer.
> This doesn't express the question you have anywhere clearly enough.

My English is so poor that I don't understand...
> Linux can run perfectly happily without any form of windowing
> environment.

I know, but nowadays almost any relevant application has a GUI.
> Do you want to replay against qt applications? KDE? wx? GTK?
> Or send raw X11 events? The answers to these questions aren't
> linux specific either...

I have nothing against GUI and in fact I chose Qt also if I made
only limited tests using Qt Designer. However I should prefer not
to program at low level (sending raw X11 events...).
Being a newbye I was confident that someone had already developed
a macro language for Linux...
I hoped to have found it in Python, but I was wrong.

Alex said:
> Actually, if the app is running under X11 you may try to fake out a
> keystroke event (with low level calls, but ctypes might let you use
> it from Python). Of course, the app WILL be told that the keystroke
> is fake, through a special flag if it cares to check for it,
> for security reasons; but if the app doesn't specifically defend
> itself in this way.
> See, for example, http://xmacro.sourceforge.net/ -- I guess that
> xmacroplay could pretty easily be adapted, or maybe even used as is
> with an os.popen.

My answer is the same as that given to Michael about low level
programming.
But I must thank anyway Alex for giving informations to such a level
(I didn't know that under Linux there was such a level of
sophistication with the possibility for an application to discover fake
keystrokes...).

If this fake keystroke is used to fire an event (like pressing a
button), the fake flag is propagated to the action taken by the button?

For the other Alex observations (about Mac OsX and my examples of
automation centered on web automation) I have a PC, and the fact that
Python is very good at dealing with the web, doesn't help too much
in this case...
In any case a macro language like AutoIt is a general purpose
application.

At last I must thank Mike Meyer for his suggestion to use python-xlib
to avoid low level programming...

Bye.
 
M

Mike Meyer

My answer is the same as that given to Michael about low level
programming.
But I must thank anyway Alex for giving informations to such a level
(I didn't know that under Linux there was such a level of
sophistication with the possibility for an application to discover fake
keystrokes...).

If this fake keystroke is used to fire an event (like pressing a
button), the fake flag is propagated to the action taken by the button?

The action is internal to the application, so whether or not it
propogates the "fake" flag is up to the application. In between the X
event and the action is the GUI library, which may also choose to not
propogate the flag.
For the other Alex observations (about Mac OsX and my examples of
automation centered on web automation) I have a PC, and the fact that
Python is very good at dealing with the web, doesn't help too much
in this case...
In any case a macro language like AutoIt is a general purpose
application.

At last I must thank Mike Meyer for his suggestion to use python-xlib
to avoid low level programming...

Just to clarify - python-xlib will let you avoid the need for C
functions to do things like send X events. In that sense, it helps you
avoid low-level programming. On the other hand, you're still sending X
events, so in *that* sense, you're not avoiding low-level programming.

In general, application scripting facilities are one thing that Unix
hasn't dealt with well. Windows and OS X both do better (but neither
do as well later versions of AmigaDOS). Whereas those systems come
with a (or a selection) mechanism that applications can use to allow
macro programming, Unix doesn't, so each application is left up to
it's own devices. The most popular solution is to embed a custom
language for scripting - which is where something like Python comes
in. Some of them now export APIs that can be hooked up to a variety of
languages. IIRC, Gnome has embraced CORBA as an interface for such,
but it didn't seem well supported the last time I looked. The bottom
line is that when it comes to scripting applications on Unix, your
solution is going to be tailored to the application.

The Unix variant with the best system-provided scripting facility is
probably Plan 9. Some Linux variants are moving in that direction, but
I don't know of any Linux applications that provide support for it.

<mike
 
S

SPE - Stani's Python Editor

some future Firefox version might perhaps integrate a Python engine

For those who never heard about Firefox 1.9, check the following urls.
It looks very promising:

1) http://wiki.mozilla.org/Roadmap_Scratchpad#Python_for_XUL

Python for XUL

Significant potential contributors in both the Python and XUL
application development communities have long wanted access to Python's
set of libraries and its capabilities as an application development
language. So in addition to JavaScript, which is the default web and
XUL scripting language, we plan to extend the reach of Gecko and XUL to
the Python world.

Mark Hammond's work on PyXPCOM and a language-neutral DOM is well under
way as of October 2005, and we believe that the glue code and bindings
will be slim enough to be part of a default XULRunner or Firefox
distribution when the 1.9 cycle is complete.

(N.B.: Mozilla does not intend to distribute the C-Python runtime with
its applications or frameworks, and application developers who wish to
take advantage of these capabilities will need to provide for this
dependency in their installers or packaging. Stub or streaming
installer capabilities in the Firefox/XULRunner based on Gecko 1.9 will
probably help a great deal to ease the extra download for Python-less
users.)

2) http://weblogs.mozillazine.org/roadmap/archives/008865.html

Given evolving JS, why Python? Simple: different programming languages,
of different ages, have their strengths, and one of the greatest
strength of any solid language is its community. We want to support
Python as well as JS for XUL scripting in order to engage a large,
creative community of hackers that is mostly disjoint from the
web-standards-savvy XUL hackers who are already engaged with Mozilla
and Firefox.

*
Stani
 
A

Alex Martelli

For the other Alex observations (about Mac OsX and my examples of
automation centered on web automation) I have a PC, and the fact that
Python is very good at dealing with the web, doesn't help too much
in this case...

All of your sensible use cases were about the Web; the fact that you
have a PC is irrelevant to this observation.
In any case a macro language like AutoIt is a general purpose
application.

"General purpose" is, I believe, an overbid here -- if what you're doing
is simulating keystrokes, you're limited to the purposes that can in
fact be achieved through keystroke-simulation. And I've pointed you to
an application that can run under Linux to simulate keystrokes (which,
of course, applications are able to detect as being simulated, if they
want to implement very strong security on this plane). What, exactly,
is stopping you from using Python to drive that application, if the
simulation of keystrokes is the pinnacle of your heart's desire?

If what you're whining about is that Linux applications can be built to
be secure (rejecting fake keystrokes, among other things), then stick
with Windows and its endless flood of malware. If you want security,
don't complain about the existence of security.


Alex
 
H

has

Alex said:
Don't neglect MacOSX -- it's quite secure, there are many open and free
applications, AND it has a decent architecture for the kind of tasks you
want to do (mostly intended for Apple's own Applescript language, but
all the interfaces are open and easily available to Python, which is
quite well supported on the Mac).

FWIW, there's a nice overview of the Open Scripting Architecture at:

http://www.cs.utexas.edu/users/wcook/papers/AppleScript/AppleScript95.pdf

It's not a perfect system and the quantity and quality of support
varies from application to application and language to language, but I
reckon the other *nixes could still learn a thing or two from it.

HTH

has
 
Q

qwweeeit

I am further commenting on new replies.

Mike said:
In general, application scripting facilities are one thing that Unix
hasn't dealt with well.
...so each application is left up to it's own devices.
Some of them now export APIs that can be hooked up to a variety of
languages.

Now I understand why I have found so many difficulties!...
An example of APIs is those available for better controlling Google
search engine.

Unfortunately all that leaves the need of specific programming for
each case... I am obliged to learn C++ and Qt (in particular
inter-process communication).

About SPE, he is a little beside the point, but I insisted so much on
web examples...

Alex said:
"General purpose" is, I believe, an overbid here --

Perhaps you are right, but for me a macro language
(like for ex. AutoIt) is very general, being only a mean of emulating
the user, running automatically external applications.
applications are able to detect as being simulated, if they
want to implement very strong security.
If you want security, don't complain about the existence of security.

Never complained... I was only favorably impressed by the
sophistication reached for assuring stronger security.

At last a new entry (has) completely off the point (FWIW > FICCL!...).

Bye.
 
J

Jorgen Grahn

On 29 Oct 2005 17:25:58 -0700 said:
Michel wrote: ....

I know, but nowadays almost any relevant application has a GUI.

Side note: lots of people would disagree with that. For example, from my
perspective, almost all relevant applications /lack/ a GUI. (And some that
has one would be better off without it.)

/Jorgen
 
S

Sybren Stuvel

(e-mail address removed) enlightened us with:
I know, but nowadays almost any relevant application has a GUI.

I can't think of any relevant server application running on Linux that
has a GUI. My text processor, email client, Usenet client, IRC client,
address book and agenda are all without GUI too.

Sybren
 
M

Mike Meyer

Jorgen Grahn said:
Side note: lots of people would disagree with that. For example, from my
perspective, almost all relevant applications /lack/ a GUI. (And some that
has one would be better off without it.)

This brings up an interesting point for scripting unix
applications. One common approach is to provide the application
functionaliity in a library, then wrap that in various ways, of which
a GUI is only one. You "script" the application by wrapping the
library for your favorite scripting language, and the script will never
open a GUI. In fact, it'll work fine in an environment where the GUI
couldn't open at all.

<mike
 
G

gmilas

Imagine you want to access a big database from a html server which
only allows you to access such data in chunks pressing a "next"
button on an ASP file. It will take several hours to click the button
and then save the new data supplied by the server!
That is a typical task of AutoIt, very easily programmable,

This may be of some use for you:
- http://www.idyll.org/~t/www-tools/twill.html a python tool with a
language to script "web commands"
- http://maxq.tigris.org/ a java tool with python as macro-language
to script "web commands"

I would guess, probably any tool designed for testing be it web or gui
should have some of the functionality you are looking after?
 
Q

qwweeeit

I didn't want to replicate any more, expecially
because the last replies (Jorgen Grahn,
Sybren Stuvel and Mike Meyer) have taken a
direction that doesn't interest me (GUI or not GUI?),
but I must thank gmi for his contribution.
This may be of some use for you:
- http://www.idyll.org/~t/www-tools/twill.html
a python tool with a language to script "web commands"

I downloaded the last version of twill (0.7.3)
and tried to apply it to get data from an asp file.
I only succeeded in getting the first 2 chunks of data,
out of almost 200, but it is the first time that I see
an opportunity to make real web automation...

Bye.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,787
Messages
2,569,627
Members
45,328
Latest member
66Teonna9

Latest Threads

Top