Altering "Send To" on Windows with Python - python

I need to redirect the "Send To Mail Recipient" menu in Microsoft Office (primarily Word and Excel) to send the document using a web client email. I need to do the same thing with the context menu that appears when right-clicking a file (i.e. Send To -> Mail Recipient).
I'd like to catch these events using Python, probably via PyWin32 via COM or ctypes. Does anyone know how to do this sort of thing? I'm using Windows XP and Python 2.6. Thanks!

the only thing I can think of is to use Microsoft Active Accessibility bindings for Python. These give you the ability to monitor events, including window open/close events. I can't think of any other library that has this functionality.
http://www.cs.unc.edu/Research/assist/doc/pyaa/public/pyAA.AA.AccessibleObject-class.html
I won't kid you. This is not a pretty solution, but it can work.
here's another description:
http://web.archive.org/web/20080510165211/mindtrove.info/articles/gui-automation-with-pyaa/

Related

On button click send character to background application

I'm trying to implement numpad in PyQt5 and Windows 10. There are buttons 1, 2, ... 9, enter
I'd like to implement the following event:
When user clicks for example on button 1, the character '1' will be sent to background application (for example notepad).
I have done simple GUI. I only need to implement this event. What libraries, functions can I use to this purpose?
You should research how Inter-process communication works and APIs.
You did not specify which Operating System you target, each one has its own ways to do it.
You mention "sending characters to notepad" but which application do you plan to communicate with ? Because working with any application may be a very difficult problem.
For Notepad I found this question that uses the Windows API to communicate, but it was relatively easy because the source language was C# (which is well-integrated with Windows). According to this other question you should use PyWin32 to do that in Python.
But if you plan your NumPad application to work with many other applications, you should look how other Input sofwares work. It may have clues how to do it.

How do I control a non-browser window that is part of Firefox?

I'm on OSX using Python 2.x, Selenium & Firefox
I'm automating testing a javascript webapp with Python & Selenium.
One of the links (Add File) in the application opens up a non-browser firefox window titled "File Upload" which looks like (/is?) a Finder window.
Is there a way that I could locate and control this window from my python script? I know Selenium can't do it, but I wondering if it might be possible with something like 'import applescript' and if so how?
I found atomac which allows me to control mac apps through their accessibility controls (which needed to be enabled on Mavericks for Aptana in System Preferences -> Security & Privacy -> Privacy -> Accessibility). Cool tool, but the documentation is pretty sparse. The examples provided on the page above got me to the point where I could close the window via the cancel button, but I had to review the function definitions in atomac's AXClasses.py to figure out the rest. Here's the solution.
import atomac, time
from atomac.AXKeyCodeConstants import *
# to allow me to make firefox frontmost while testing
time.sleep(5)
# get a reference to the running app
firefox = atomac.getAppRefByLocalizedName('Firefox')
# get the window of the reference
firefoxwindow = firefox.windowsR()[0]
# send key sequence to go to my home folder
firefoxwindow.sendKeyWithModifiers('h',[COMMAND,SHIFT])
# send key sequence to select first file there
firefoxwindow.sendKeyWithModifiers('a',[COMMAND])
# press the now active Open button
openbutton = firefoxwindow.buttons('Open')[0]
openbutton.Press()
It's theoretically possible, but really awkward. I'll give you a bunch of links--not ideal, I know, but you could write a book on this.
You'd need to start by enabling AppleScript control of the GUI. Then you'll want to read up on how to control the GUI from within Applescript. However, you wanted to use Python and not AppleScript, so then you'll need to install PyObjC, which is a Python to Cocoa bridge. You'd need to use the Scripting Bridge framework and figure out (from the extremely thin documentation) how to translate the AppleScript docs to Python.

Kiosk mode in wxpython?

Is there a way to create a 'kiosk mode' in wxpython under Windows (98 - 7) where the application disables you from breaking out of the app using Windows keys, alt-tab, alt-f4, and ctrl+alt+delete?
If an application could do that it would make a great denial-of-service attack on the machine.
In particular Ctrl+Alt+Delete is the Secure Attention Sequence. Microsoft goes to great lengths to insure that when the user hits those keys, they switch to a secure desktop that they can be confident that the logon box is the real Windows logon and not a counterfeit.
What you need to look at isn't functions that your application can call, but System Administration options that allow an Administrator to configure a machine for limited use. These exist, but it's more a question for Super User than for Stack Overflow.
This should get you started
http://msdn.microsoft.com/en-us/library/aa372139(VS.85).aspx
wxPython alone cannot be done with that.
You need to do Low Level Keyboard Hook with C/C++ or with equivalent ctypes, for
Windows keys, alt-tab, alt-f4,
but Ctrl-Alt-Del, I don't think so for Windows XP and above.

Python Send Keystrokes to Non-Active Application

I'm automating some common GUI tasks I have to do in an application, and I'm using a Python program and SendKeys to do it. So far I've had to activate the application I'm sending keys to (since SendKeys just sends the keystrokes to the active window), but I'd like to be able to send keystrokes to an application in the background. Is there a way to do that, or am I dreaming an impossible dream?
Thanks for your help.
pywinauto is another MS-only GUI automation tool, this one written in Python.
SendKeys is a Python module for Windows that can send one or more keystrokes or keystroke combinations to the active window.
If you need to do some automated work in the background, make another user/session and do it in that.
However if you must do something of this like on windows, I always reach for autoit.
It's M$ only and perfectly suited to automating tasks on that OS.
This is a frequent question in the autohotkey.com forums. Search under
"sending commands to controls". Basically, if you have the control ID, then it doesn't need to be visible in order to operate on it. There're more details on the forums.
good luck!

Detect windows logout in Python

How can I detect, or be notified, when windows is logging out in python?
Edit:
Martin v. Löwis' answer is good, and works for a full logout but it does not work for a 'fast user switching' event like pressing win+L which is what I really need it for.
Edit: im not using a gui this is running as a service
You can detect fast user switching events using the Terminal Services API, which you can access from Python using the win32ts module from pywin32. In a GUI application, call WTSRegisterSessionNotification to receive notification messages, WTSUnRegisterSessionNotification to stop receiving notifications, and handle the WM_WTSSESSION_CHANGE message in your window procedure.
If you're writing a Windows service in Python, use the RegisterServiceCtrlHandlerEx function to detect fast user switching events. This is available in the pywin32 library as the RegisterServiceCtrlHandler function in the servicemanager module. In your handler function, look for the SERVICE_CONTROL_SESSIONCHANGE notification. See also the WM_WTSSESSION_CHANGE documentation for details of the specific notification codes.
There's some more detail in this thread from the python-win32 mailing list, which may be useful.
I hope this helps!
In a console application, you can use win32api.SetConsoleCtrlHandler and look for CTRL_LOGOFF_EVENT. In a GUI application, you need a window open and wait for the WM_QUERYENDSESSION message. How precisely that works (and if it works at all) depends on your GUI library.

Categories

Resources