我想寫一個程序,可以:程序自動化軟件使用
打開一個應用程序。 (我使用subprocess
模塊成功執行應用程序)
使用該應用程序。 (如何在特定軟件上自動執行任務?是否有可能?例如,軟件需要我登錄和python,並自動使用我的憑據登錄,並繼續使我的典型用法(如打開項目)自動化)
關閉應用。
from datetime import datetime
import time
import os
import subprocess
os.chdir("../../Desktop/Sublime/Sublime Text 2") #Directory need to adjust to find teamviewer
print "Starting python..."
switch = True
activator1 = True
activator2 = True
startBoolean = True
exitBoolean = True
container = None
def startTimer(startTime , exitTime):
global dateTime
global startBoolean
global exitBoolean
dateTime = datetime.now().strftime('%H%M%S')
print "Current Time: " +dateTime+ "| Start Time: " +startTime +"| Exit Time: "+exitTime
if dateTime >= startTime:
startBoolean = False
print "start boolean: "+ str(startBoolean)
if dateTime >= exitTime:
exitBoolean = False
print "exit boolean: "+ str(exitBoolean)
return [startBoolean,exitBoolean]
def startApplication(startTime):
if dateTime >= startTime:
print "Launching Application..."
process = subprocess.Popen(["./sublime_text"],shell=True) #This is using ubuntu terminal command. Might need to change the command to fits other OS.
def stopApplication(exitTime):
if dateTime >= exitTime:
print "Exiting Application..."
process = subprocess.Popen(["killall sublime_text"],shell=True)
startTime = raw_input("Project Launch Time: ")
exitTime = raw_input("Project Exit time: ")
while switch:
startTimer(startTime , exitTime)
global container
container = startTimer(startTime , exitTime)
if container!=None:
if activator1==True:
if container[0] == False:
print "clear1"
activator1 = False #Cannot activate < 1.
startApplication(startTime)
if activator2==True:
if container[1] == False:
print "clear2"
activator2 = False #Cannot activate < 1.
stopApplication(exitTime)
如果您在Windows上,您可能需要考慮AutoHotKey(http://www.autohotkey.com/)而不是Python來自動化軟件使用。請小心將您的憑證存儲在某人可能能夠閱讀的文件中。 –
大家好。我剛剛發佈了我的所有代碼。我只是崇高的例子。 –
@geoffreykoh我可以知道什麼輸出你的專業! – Ravichandra