Can I run a Python script targeting only a certain application (screen)? - python

As I mentioned in the title, I want a feature such as applications that target a certain screen and only target that screen in applications that take more screen recordings or in applications where we share screens such as google meet.
In short, I opened the word file and I write something here every 10 seconds with a python script, but when I put this word file in the background, I want the relevant python script to run on this word file again and not interfere with my other works. Is this possible ? How can I do that ?

Related

Python: Different Files for Different Tasks?

I'm working on an app that has several buttons (10+) on the home screen that take the user to different pages with different functions, like home screen on Android or iOS where apps are located. The problem is, if all the different functions accessed from the home screen were to be put into one file, it would end up being over 10,000 lines in a single .py, which I've read is not good practice and can slow down the process.
How would one make it so that when the user presses a button for a task on the home screen, it accesses the code from a different .py without opening up a new window?
Thanks for your help!

How to make python program run automatically every time I download a file?

I want to create a program that runs automatically every time I download a file from browser.
For example, when I download an image file from chrome, the program runs automatically and perform tasks. Is it possible?
You could have a script using len(os.listdir()) to see how many files are in your downloads folder, and anytime that number changes, perform your desired operation on the newest file
EDIT:
You'd want a Python script looking something like this:
import time
import os
While True:
NumberOfFiles=len(os.listdir("C:\Path\To\Downloads\Folder"))
time.sleep(20)
OldNumber = NumberOfFiles
NumberOfFiles = len(os.listdir("C:\Path\To\Downloads\Folder"))
if NumberOfFiles != OldNumber:
#This is where you put the lines of code you want executed when you download something.
And then you'd need a .bat file with something like
C:\Path\To\Python C:\Path\To\That\Script
You could put that .bat file in your Startup folder, or use the Task Scheduler utility to make it start running everytime you log on to your computer.
Hope this helps! At the moment it checks for new files only once every 20 seconds. You could make that check more often by lowering the number there, but the more often it checks, the more resources this is gonna use. If you don't download things to often, I'd even suggest changing it to something like 60
I think you need some kind of "listening" script running on background which will monitor files in download directory

Keep track of which files are created by a certain process

I'm using a Python (3.3) script to run a command that will render a whole bunch of image files for an animation film.
While it's rendering, it creates an empty image file every time it starts a new frame of the animation, and when it's done rendering that frame, it saves the image over that empty file and moves onto the next frame.
The python script starts this rendering process by running another script using:
proc = subprocess.Popen(cmd, shell=True)
Is it at all possible to check which files were created during this process?
The reason being, someone may wish to stop the render before it finishes, but when they do so there will be an empty image file left over. I'd like to have the script delete the empty images when the big red Stop Render button is pushed, but I cannot simply delete all empty images because there may be other computers rendering - the empty images are there to prevent multiple computers rendering the same frame (they skip that frame if the image file for it exists).
If it helps, all the computers use Windows 7, and the animation program that does the rendering is Maya (2014).
If there's no easy way, I'd be happy to use any kind of ugly hack to get the job done :)
If you are doing this in Maya, you can use mayapy interpeter that comes with Maya (rather than mayaBatch or maya -r). Inside of standalone you can run any script(s) you need to setup the render, execute it, and post-process the results. At a minimum, that will let you handle one frame at a time and use python to submit the images one at a time.
A basic setup would be:
Create a python script that does what you need to do and works correctly inside the maya python interpeter. The script will be run as if it were in the maya listener, so you can import maya.cmds and use maya features as needed.
If the script needs command line arguments, use sys.argv to retrieve them. When you run the script, any arguments you pass in will be available in sys.argv.
Your script can get access to all of Maya's functionality by importing maya.standalone and calling it's initialize method (more details here)
From the command line, run the mayapy.exe that lives in the bin folder of your maya install. The -s flag allows you to specify a script to run, so you'll pass in the python script as an argument, followed by any other arguments you need: something like "path/to/mayapy.exe" -s "path/to/yourscript.py" arg1 arg2 arg3.
You won't be able to catch a user cancelling via control-c but you could request cancellation from outside using a TCP connection to the maya command port, or even just by prompting for user input after each frame
For a fancier operation you can run an rpc server inside your Maya using something like ZeroMQ or RpyC. You could also make your own with a WSGI server listening to the http port.
You can also look in to 3d party render management systems. There are some open-source ones here

Is it possible to get current application running with python script

I am very much concerned about my productivity all the time. I have recently come across this beautiful chrome extension Limitless
But this is only measuring what i'm doing within the chrome application. As I work most of the time with pdfs, videos etc, I want to develop similar application for linux(ubuntu) desktop enviroment.
Basically I want the script to run continuously as long as the workstation is on.
It should be able to know what I'm currently looking at (for eg a pdf file or a lecture video in vlc) and get the name of the respective file, start time, end times etc and finally post to db.
It is better if it could know if the system is idle or at sleep.
I don't have slightest clue at bash scripting. so my questions is could this task be accomplished with python.
What I've tried?
I started with a search in google "get current application python", "current window title python" etc etc and really surprised to see absurd results.
Please give me pointers on this.
I think you are asking for vocabulary. So I give you what I know.
You are using Ubuntu so your Window Manager may be Gnome.
The window manager knows which window has the focus.
So maybe you want to find out which window has the focus and you want to map it to the Process that opened the window.
What you need to focus on is is module for Python or a Python Binding for the window manager. This module is likely to also be able to control the windows.
The window manager is started with startx.
You could try to call a command line tool and catch the results
How do get the process list on command line:
https://stackoverflow.com/questions/53489/how-do-you-list-all-processes-on-the-command-line-in-windows
And how to call a tool with python:
Python subprocess.call and subprocess.Popen stdout
[edit] Repeating the call in Intervals and counting the intervals a process were running gives you a good estimation of running time of a process...
[edit2] As GreenAsJade said, you search a way to find out which windows has the focus.
See How do I detect the currently focused application?

Detect Areas of Text in Screenshot

I'm working on a project to increase the ability for wine to automatically test software packages. What I'm looking to do now is detect text in the screen capture of the current window. I can then parse all of the text and use autohotkey to give a mouse click on the coordinates of the text I want.
For example, in firefox, I might want to test different things, the first open being opening preferences. I would then need to parse the screenshot of firefox, detect all of the separate locations of text. I can then run these separate images of text into tesseract-ocr and detect which one, says "Edit". I then redo this again for "preferences".
I've tried to find a solution but so far can't find anything. I'd prefer a solution that uses python or has python binds as thats what I've been programing in so far.
A possible starting point is Project SIKULI. It is a tool to automate GUI testing. It is written in Java, nonetheless it includes a scripting environment based on Jython, hence modifying it to support python script may be not too difficult.

Categories

Resources