What Language To Use To Manipulate OSX Application Windows? - python

I'm sure many of us have seen vision degradation from too much screen time from programming.
A theory suggests that when they eyes become fixed, tension builds. And that tension causes the vision to slowly degrade.
This software promises to prevent that fixation...
http://www.central-fixation.com/downloads.php
The problem is it's outdated, and Windows only.
I'd like to write a script that will "swing" all open windows according to a set pattern & speed. A script that works with OSX 10.9 and later.
I know Python and Javascript but have no idea where to start on this.
Please help me out.
How is it done? What language is used to manipulate OSX application windows? And/or simply manipulate the whole desktop window space?

I haven't tried to do exactly what you are trying to achieve here, but ANYTHING at all related to manipulating OS X should be done via Automator or AppleScript. If you are running Yosemite, the app is called "Script Editor". Anything older and it's called "AppleScript Editor".
Try this site.
Extract:
tell application "Finder" to set the position of the front Finder window to {94, 134}
I know your question is labeled "python" but I believe that AppleScript is the way to go with this.
You can add AppleScript to an Automator workflow with the "script" object. I'm not sure how to make this run periodically, but one option would be to keep it open in the background. You can do this in AppleScript with the delay command:
(do stuff here)
delay (your delay)
Hope this achieves your purpose.

Related

Python - Interact with program´s GUI OFFSCREEN

I know this is too greedy, but i want to make python interact with a program´s user interface but on the background, so that i can still use my computer while the code runs. I am currently using pywinauto and pyautogui. So I can´t work while the code is running because my mouse and keybord are being manipulated. Does someone know how to make my code manipulate a "second" mouse and keyboard on the background while I use my mouse and keyboard to do other things?
The most common way to do this is a remote execution (on dedicated server or on virtual machine). All known recipes for pywinauto are collected in the Remote Execution Guide.
More complicated way is trying to use silent methods of pywinauto that don't require active desktop. This is partially mentioned in the above guide, but requires deep knowledge of pywinauto and your application structure. One of the examples was discussed on StackOverflow: https://stackoverflow.com/a/32847266/3648361 This way is not possible for many kinds of applications.
I've never heard about "second mouse/keyboard" approach. Not sure it's technically possible at all.

Using python to automate external program

Whats the best Python library to automate an external program
We have accounting software where we need to upload many files into for a particular reason. To do this we search for the relevant menu item right click it and then import. This is time consuming. It would be useful to be able to automate this. Ive looked at pyautogui but it needs the screen to be active and the user cant do anything else on their machine while it is running.
Of course ideally I would like to use the accounting software's API (if there is one) or find out if the upload is running a stored procedure at the back end taking the filepath as a parameter and then calling this procedure myself.
In the absence of those would anyone know if there is a way to automate this in Python without the limitations above or if not in Python what other language would be good for this?
Many thanks
I haven't done such thing. So I do not have proof of concept. But
You have at least 2 options, more or less complicated:
install virtualbox/vmware, and create virtual operating system (windows or Linux) on it. Then run your pyautogui script in this virtual operating system. You operating system is available in window-like container - so you can minimize this window with running script, and you system where you can interact as a user. (long tutorial: https://www.virtualbox.org/manual/ch01.html)
If you are Linux user, then you may be familiar with virtual screen. I think many people are using this virtual screen with automating web testing in sellenium (How do I run Selenium in Xvfb?). So probably, I say probably, there is chance to run pyautogui in virtual screen: How to attach pyautogui to the virtual display? - this is similar, but not answered question.

Making python terminal user interface

I'm trying to make terminal user interface with python which I will use it as post installation script for min linux os. But I don't want to use ncurses or urwid because it feels like overkill. I'm looking more in whiptail or screen direction. But I don't know is it better to call ui terminal rendering from python subprocess or to use it with python bindings like pythondialog, here are the reasons for my doubts.
Is whiptail/screen available on every minimal linux image... subprocess should be better suited for my program.
pythondialog requires installation of python3-dialog package. Since I want to make a postinstallation program for linux min image I want to use dependencies as little as possible.
What would you suggest for my problem?
Maybe npyscreen is what you are looking for, but i havent tried it. It just installed for me in fresh 2.7 virtualenv with zero dependencies - EDIT: sorry no, it runs on top of ncurses.
I've had a similar notion about ncurses or urwid. You might want to try:
prompt toolkit - focus on UI, comes with tons of examples
asciimatics - handy for UI and animations, also with a bunch of helpful examples
Both have a responsive and active community.

How to run a Python script in something other than cmd?

I have written a program. I don't know if it is important how it is written but you can find it here: http://pastebin.com/Z3ZvVPV8 Basically, it asks you to assign values to variables and will perform calculations depending on what variables you chose, and prints the answer.
I would like to know how I can make the program run in a window other than cmd (I am using Windows Vista 32bit). I don't need much at all in terms of GUI, just a window that is a bit more user friendly/easier to look at when they are using the program.
EDIT: To those suggesting using IDLE, while that would work for me, if others want to use the program they would have to download it, so I was hoping for a way for that not to happen.
Python comes with a sort of default GUI package TkInter you can use it.
Also there is a lot of other GUI packages available.
The Python standard library offers a lot of ways to implemt simple (but also rather complex) GUIs. I'd like to point you at the documentation of TK (tool kit for graphical interfaces) http://docs.python.org/library/tk.html where you will find also some useful example of use.
Py2Exe is a viable option if you really don't need a gui. This will make it run and look like a command prompt, but it will be an .exe file. Here is a quick quote from thier page: "py2exe is a Python Distutils extension which converts Python scripts into executable Windows programs, able to run without requiring a Python installation."
Another alternative is to get Portable Python. Here is a quote from thier webpage: "Portable Python is a Python® programming language preconfigured to run directly from any USB storage device, enabling you to have, at any time, a portable programming environment. Just download it, extract to your portable storage device or hard drive and in 10 minutes you are ready to create your next Python® application." After packaging the portable python and your .py or .pyc file then create a .bat file that runs the portable python "Python-Portable.exe" with the correct command line parameters for loading your script. Be sure to use relative paths in the batch file in case they are running it from a flash drive, or something other than the same location as you.
NOTE: This is really not a good way to do this as thier download page states: "Installed size: based on selected packages, between 49MB and 480MB". Also be sure to read the the current Python Software Foundation License, as that is what Portable Python is released under, and it may or may not be legal to package it in a closed source project. I haven't really looked at the license myself to be able to tell you. If you are releasing it as open source, then there would not be an issue though. As a quick side note, if you need that .bat file to be a .exe file then you can use a .bat to .exe converter battoexe.com is one. This is really going the long way about doing the whole thing, but it is an option.
Sources:
Working with Python on and off for 7 years now, a lot that using a portable version on a flash drive, and also dealing with Batch files much longer.

Python front-end GUI for Linux

I'm planning to take a non-GUI Linux distro (no Gnome, KDE, etc) and build my own front-end GUI for it. While I have a few years of Python programming experience, I have never attempted to do something quite like this.
To be more specific about my project, I'm building a CarPC and I have everything pretty much worked out so far, except the front-end. Most pre-existing front-ends for CarPCs run on Windows and the ones that run on Linux are hard to find (they either quit development or only run on specific hardware). My front-end will always be full-screen and I do not want to run a desktop environment unless I absolutely have to; it would just slow down the boot time and provide unnecessary features.
My question is basically where I should start. What Python graphics libraries are out there that would allow me to build a front-end GUI without a desktop environment?
You'll probably want to look at other answers and questions on this topic such as this one
Another good link is this one on the Python websitewhich lists different GUI toolkits.
While I haven't used it, Kivy looks like a good place to start. It's apparently got touch screen capabilities which I assume you would use and it doesn't look constrained to a GUI desktop env.
Hopefully you can find a way to do this without a desktop env. If not perhaps consider using X11 as your layer and go from there.
You should probably consider DirectFB. You can even use a DE on it if you like (although not required).
WxPython is awesome. I use it with Python and plain WxWidgets in C++ too. I've had great luck with making native GUIs from it and internationalization is supported too. Good luck!
Edit: I missed the "without a desktop environment bit". I'm not sure my answer is relevant. You should edit the Title of the question. Just disregard.

Categories

Resources