I'm trying to move a program's window to 0,0 location so this is my code:
Run, C:\Program Files (x86)\ThunderSoft\DRM Protection\CPMaker.exe
WinMove, ahk_exe CPMaker.exe, , 0, 0
and this is Window Spy's information:
the first line of the code works but the moving part doesn't. I tried it with ahk_class TfrmMain too.
Problem solved by adding this line:
WinWait, ahk_exe CPMaker.exe, , 5
this line waits for the program to start the first parameter is WinTitle and the last one is the timeout in seconds.
the code still didn't work because of permission issues so I had to run it as admin, now it's working.
Related
Sample script:
#NoEnv
#Warn
#SingleInstance Force
#IfWinActive Foo ahk_exe foo.exe
!A::Send Foo
SetTitleMatchMode Regex
#IfWinActive Bar$ ahk_exe bar.exe
!A::Send Bar
When running it, the interpreter throws:
I want to apply SetTitleMatchMode Regex only to bar.exe, is it achievable without putting it on top of the script?
Quote from SetTitleMatchMode Remarks:
Every newly launched thread (such as a hotkey, custom menu item, or timed subroutine) starts fresh with the default setting for this command. That default may be changed by using this command in the auto-execute section (top part of the script).
And quote from The Top of the Script (the Auto-execute Section):
After the script has been loaded, it begins executing at the top line, continuing until a Return, Exit, hotkey/hotstring label, or the physical end of the script is encountered (whichever comes first). This top portion of the script is referred to as the auto-execute section.
I am trying to use Remote Debugging of ZeroBrane to debug my application.
I don't want users add any extra codes to their scripts. So when a user click the debug button, at the C side, first, I set the path and call the mobdebug lib, then I try to execute the user code:
luaL_dostring(L, "package.path = package.path .. ';./scripts/lualibs/mobdebug/?.lua;./scripts/lualibs/?.lua'");
luaL_dostring(L, "package.cpath = package.cpath .. ';./scripts/bin/clibs/?.dll'");
luaL_dostring(L, "mobdebug = require('mobdebug').start()");
luaL_dofile(L, FileName);
It works fine for the official lua 5.1 intepreter. The debugger stops at line 1 of the source file. But if I switch to luajit, the zerobrane prompts "Debugging suspended at 'mobdebug.start():1' (couldn't activate the file).". Then I click "step over", the script file can be activated and the debugger stops at line 1.
Is there any way to skip the error message and directly activate the source file when using luajit?
You may want to set debugger.runonstart = true to continue execution without stopping at the first line (documentation), but you will need to use breakpoints or Project | Break to suspend the execution when the debugging is started.
I'm writing a startup script that starts and logs in on all my applications I use daily. For this I'm using the PyAutoGui module, python 3, and another application that manages the layout of my windows on my 2 monitors.
def smv(username, hotkey):
# starting application
os.system("smv.exe")
# it autofocuses on the username field
pyautogui.typewrite(username)
# (passwords are the same)
pyautogui.typewrite("PASSWORD\n")
# move to the window header (where title, minimize, close, etc..)
pyautogui.moveTo(100, 10, duration=0)
# drag the window to the far right of the primary monitor (since pyautogui doesn't support multiple monitors)
pyautogui.dragTo(1910, 20, duration=1, button="left")
# press the hotkey that belongs to the window layout manager
pyautogui.hotkey("ctrl", "alt", hotkey)
smv("username", "num7")
smv("username2", "num1")
The weird thing is that the first smv() runs perfectly fine. Application starts up, logs in, moves the window and adjusts the position/size with the hotkey.
The problem occurs when the second smv() runs. Application starts up, logs in, moves to window header, but then crashes with:
Traceback (most recent call last):
File "main.py", line 15, in <module>
smv("username2", "num1")
File "D:\files\PyCharm\startup\smv2.py", line 10, in start
pyautogui.dragTo(1919, 10, duration=1, button="left")
File "d:\PortableApps\Miniconda3\lib\site-packages\PyAutoGUI-0.9.33-py3.5.egg\pyautogui\__init__.py", line 683, in dragTo
File "d:\PortableApps\Miniconda3\lib\site-packages\PyAutoGUI-0.9.33-py3.5.egg\pyautogui\__init__.py", line 274, in mouseDown
File "d:\PortableApps\Miniconda3\lib\site-packages\PyAutoGUI-0.9.33-py3.5.egg\pyautogui\_pyautogui_win.py", line 393, in _mouseDown
File "d:\PortableApps\Miniconda3\lib\site-packages\PyAutoGUI-0.9.33-py3.5.egg\pyautogui\_pyautogui_win.py", line 480, in _sendMouseEvent
PermissionError: [WinError 5] Access denied.
I'm cracking my brain trying to figure out why it crashes at the second run.
I've tried using try and except blocks (no use), I've switched the order in which the application starts (num1 before num7 and vice versa), but no use (1st one runs, 2nd crashes).
I've even tried to split them up into 2 files and running it from a third "main.py" file. Its not efficient, I know, but wanted to see if it made any difference.. you guessed it: it doesn't. It still crashes on PermissionError.
In 0.9.34, this has been fixed (or at least, the exceptions are now suppressed since the clicks still seem to work anyway). So the solution is to upgrade PyAutoGUI.
I have a data file a.dat that is updated every few seconds. I wish to plot it in gnuplot every few seconds to see the changes
plot "a.dat"
What is the easiest way to do it? Thanks.
Make a script with a loop:
while (1) {
plot "a.dat"
pause 1 # waiting time in seconds
}
Execute it with gnuplot script.gp.
For purposes of code structure and debugging, you might prefer the following alternative:
plot "a.dat"
while (1) {
replot
pause 1
}
This has the advantage that you do not have to put a complicated plot command inside the loop and do not suffer from incorrect line numbers for the plot command in error messages (that happen in at least some version of Gnuplot).
Finally, if your Gnuplot is so old that it does not yet support loops, there is the alternative:
plot "a.dat"
pause 1
reread
With reread making the script interpreter jump to the beginning of the file again.
If gnuplot is called with plot commands in the command line (option -e) instead of a command script file, only the version
gnuplot -e "...plot command(s)...; while (1) { pause 1; replot; }"
worked in my case, the other version
gnuplot -e "...plot command(s)...; pause 1; reread;"
did not.
On windows 10, I have to kill the gnuplot task in the task manager, because if I close the gnuplot window with the close-window-button, the window opens again after one second latest. Does anybody have an idea of how to handle this in a more comfortable way?
I am trying to write a batch file that starts another batch file, waits for that batch file to complete its job, and then continue once that other batch file has exited. However, when I manually close the batch file launched by the first batch file, it comes up with a prompt saying:
^CTerminate batch job (Y/N)?
Is there a way to automatically select 'N', because it needs to delete some temporary files on exit.
Purpose/Premise of Script: To be able to remove a flash drive and lock the station (hence copying files to external source).
Summary of Script:
Program Copies files to %homedrive%
Program launches another script (one of the files copied to homedrive)
After that program quits, it deletes the copied files
Solutions Tried:
Different command switches inside of START /WAIT +/I +/B (Adding /I
or /B did not produce anything useful)
Using /C and /K switches after the START /WAIT program.bat +/C +/K
(had no affect)
Well, you could use echo n | program.bat to automatically respond n to ^CTerminate batch job (Y/N)?, but an easy way to fool this method is to hit and keep pressed [Ctrl]-C.
There simply is no reliable way to disable the interruption of any program (much less a batch file). What stops the user from just closing the window?
You would want a command like this:
start /wait program.bat|echo n>nul
">nul" will hide the "n" that shows up afterwards. But there doesn't seem to be a way to stop "^C" from showing up.