Can I open windows task scheduler with Python? - python

I've just been experimenting with python so that I can make life a little more continent for myself. I tend to be doing multiple things at a time and python has been extremely helpful with moving files and opening programs. I was just wondering if there is a way it can open the scheduler, and if you can bind it to a key?

With standard os library
import os
os.system('control schedtasks')
Or for more complicated options, with subprocess
import subprocess
p = subprocess.Popen("control schedtasks")

I would try something simple like this to open the scheduler:
import os
os.system("taskschd.msc")
Note that if you don't want the UAC popup to ask you for elevation whenever your script runs, your script itself will need to be run as admin (so that every sub-process that it executes, such as the Task Scheduler, will also subsequently be run as admin).
As far as binding the script to a key...you may honestly have the most luck using something like https://autohotkey.com/ to do so. Alternatively, you could make your script run at login, and then use a package like https://pypi.python.org/pypi/system_hotkey/1.0.3 to implement hotkey watchers into it (note that this is a Python 3 package).

Related

Run Python script quickly via HotKey

I've created a simple script that executes a "moving mouse and keyboard" sequence. Although currently to get this to work I use a Shell (Idle) to run and that is to slow with boot up time and such.
Is there a way to have this python file on desktop och with a hotkey swiftly run the code? I tried doing it through terminal but it doesn't like my module.
Some info:
This is for both mac and windows.
The module I imported is pyautogui from PyPi and it works in the shell.
Thank you in advance!
Some things to consider when trying to setup a hotkey to successfully execute any kind of command:
Each Operating System has its own ways to setup hotkeys and sometimes this may differ between distributions as well as between desktop managers.
Many of the relevant how-to-descriptions are easily found via regular search machines as Google.
If you would in fact like your script to set-up its own hotkeys you would have to re-write it in such a manner that it can detect the current operating system/distribution/desktop manager by itself and execute the commands relevant to that particular set-up.

How to un-elevate permissions in windows with python

I'm trying to run commands as a particular user rather than an administrator.... seems strange, but roll with me here.
I am running my python script as an administrator, but would like to perform certain functions of the script as an underprivileged user.
For example, something like this would be what I would want to accomplish
from shutil import copyfile
as_user('testuser', 'P#$$w0rd1', copyfile(src, dst))
Other parts of the script would proceed to run as administrator. I've tried using run-as and psexec without any luck as the just end up popping open a new window entirely :|
Other than this, I have no idea how to accomplish this task on windows, with linux this sort of stuff is easy.

python or pythonw in creating a cross-platform standalone GUI app

I am developing a simple standalone, graphical application in python. My development has been done on linux but I would like to distribute the application cross-platform.
I have a launcher script which checks a bunch of environment variables and then sets various configuration options, and then calls the application with what amounts to python main.py (specifically os.system('python main.py %s'% (arg1, arg2...)) )
On OS X (without X11), the launcher script crashed with an error like Could not run application, need access to screen. A very quick google search later, the script was working locally by replacing python main.py with pythonw main.py.
My question is, what is the best way to write the launcher script so that it can do the right thing across platforms and not crash? Note that this question is not asking how to determine what platform I am on. The solution "check to see if I am on OS X, and if so invoke pythonw instead" is what I have done for now, but it seems like a somewhat hacky fix because it depends on understanding the details of the windowing system (which could easily break sometime in the future) and I wonder if there is a cleaner way.
This question does not yet have a satisfactory answer.
If you save the file as main.pyw, it should run the script without opening up a new cmd/terminal.
Then you can run it as python main.pyw
Firstly, you should always use .pyw for GUIs.
Secondly, you could convert it to .exe if you want people without python to be able to use your program. The process is simple. The hardest part is downloading one of these:
for python 2.x: p2exe
for python 3.x: cx_Freeze
You can simply google instructions on how to use them if you decide to go down that path.
Also, if you're using messageboxes in your GUI, it won't work. You will have to create windows/toplevels instead.

Python interacting with OS X - is it possible?

I'll explain my question: is it possible to write a Python script which interacts with OS X architecture in a high-level way?
For example, can I gain control on Mac OS X windows resizing from a Python script? Are there modules for that? I'm not finding any.
To push things even further, would I be able to control keyboard shortcuts too? I mean, with Python, could I write a script that opens a terminal window everytime I type cmd + Enter from wherever I am in that moment, as if it was a system shortcut (Awesome WM style, if you know what I'm talking about)?
Hope I've been clear.
The 2nd one you can't do for sure, since the events are grabbed by other processes.
You should look for a osx specific library for doing that and then write a python wrapper around it.

Running a python app alongside the live interpereter

I'm making a drawing program with python and pygame. I am trying to incorporate a script-fu thing in which the program opens a python live interpreter upon startup and allows the user to execute commands in the interpreter alongside the graphical interface.
My current strategy is to run the main loop inside its own thread, then have the application opened using a bash script that does 'python -i main.py'
Is this a safe/effective/ideal way of doing this? How can I use locks to ensure that commands coming in from the interpreter are executed between main loop iterations?
This is my first time using threads, so please explain to me like I am 7.
Thanks :)
The interpreter won't cooperate with locks you set (since it doesn't know about them). Thus, you cannot guarantee when the code entered by the user will execute.
Consider using the code module to build your own interactive console (it's really easy!). Then you can do the locking every time you go to execute user input.
Why are you using a third party live interpreter? Do you realize that pygame comes with one built in? The documentation is here. This will eliminate all of your problems quite easily.

Categories

Resources