mrkazoodle Posted June 19, 2011 Report Share Posted June 19, 2011 Basically, what I want to do is start µtorrent automatically with windows so I cannot forget to start it, but I also don't like programs running in the background when I don't need them.So I wrote a batch script and adapted a python (3.2) script which I use for deluge on linux.I let µtorrent execute the batch script (C:\Users\USERNAME\Desktop\µtorrentscript2.bat %S) which then runs the python script with the appropriate argument so that a file containing the number of downloading torrents is updated.When windows starts I let it run the python script with the start argument (a shortcut which targets C:\Users\USERNAME\Desktop\script_utorrent\utorrent_script.py -s) so that the script checks if there are active torrents and if so starts µtorrent.I might rewrite the python script so that I only need a single script, but I'm pretty happy with this result.However, would anyone know a smarter way to get the job done? I know µtorrent has a webui so I think it can be done more easily, but I don't know the slightest thing about it...Batch script:@echo offset SCRIPTLOCATION="%USERPROFILE%\Desktop\script_utorrent\utorrent_script.py"IF %1==6 (start python.exe %SCRIPTLOCATION%)IF %1==3 (start python.exe %SCRIPTLOCATION% -d)IF %1==5 (start python.exe %SCRIPTLOCATION% -d)IF %1==11 (start python.exe %SCRIPTLOCATION% -d)IF %1==13 (start python.exe %SCRIPTLOCATION% -d)exitpython script:#!C:/Python32/python.exe -uimport pickle, subprocess, syspath = "C:\\Users\\USERNAME\\Documents\\utorrent.txt"path2 = "C:\\Program Files (x86)\\uTorrent\\uTorrent.exe"try: argument = sys.argv[1]except: argument = 'void'def main (): if (argument == '--start') or (argument == '-s'): #start value = load(path) #load the value if (value > 0): subprocess.Popen(path2) elif (argument == '--decrease') or (argument == '-d'): #decrease save(adjust(-1)) else: save(adjust(1)) #default return 0def save(value): file = open(path, 'wb') pickle.dump(value, file) file.close() return 0def adjust(value): storedvalue = load(path) + value if storedvalue < 0: storedvalue = 0 return storedvaluedef load(path): #extract the value from the file try: unpicklefile = open(path, 'rb') data = pickle.load(unpicklefile) unpicklefile.close() except: #no file found; it will be created upon saving data = 0 return dataif __name__ == "__main__": main() Link to comment Share on other sites More sharing options...
mrkazoodle Posted June 20, 2011 Author Report Share Posted June 20, 2011 I realised that python isn't as popular on windows as on linux, so I wrote a bit of C++ code to replace the python script, I hope you like it #include <string>#include <fstream>#include <iostream>#include <cstdlib>using namespace std;string path = "C:/Users/USERNAME/Documents/utorrent_data.txt";string commando = "start /D \"C:\\Program Files (x86)\\uTorrent\" utorrent.exe";void save(int);int load();int adjust(int);int main(int argc, char *argv[]){ if (argc > 1) { string arg = argv[1]; if ((arg == "-s") || (arg == "--start")) {if (load() > 0) system(commando.c_str()); else save(0);} else if ((arg == "-d") || (arg == "--decrease")) save(adjust(-1)); } else save(adjust(1)); return 0;}void save(int value){ ofstream ofile(path.c_str()); ofile << value; ofile.close();}int load(){ ifstream ifile(path.c_str()); if (ifile.is_open()) { int value; ifile >> value; ifile.close(); return value; } else return 0;}int adjust(int value){ if ((load() + value) <= 0) return 0; else return load() + value;}the new batch script:@echo offset COMMAND=START /D "%USERPROFILE%\Documents" program.exeIF %1==6 (%COMMAND%)IF %1==3 (%COMMAND% -d)IF %1==5 (%COMMAND% -d)IF %1==11 (%COMMAND% -d)IF %1==13 (%COMMAND% -d)exit Link to comment Share on other sites More sharing options...
mrkazoodle Posted July 9, 2011 Author Report Share Posted July 9, 2011 srr for bumping this thread, but doesn't anyone have a better solution?Couldn't it be possible to do something similar, but better, by making an app which does the job?I have absolutely no idea how these apps are written, some info on this would be welcome as well. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.