I recently updated to AHK 2.0, and am having trouble adapating old scripts to the new syntax.
This script lets me use the capslock key to open a new tab in my default browser. If the browser isn't open, the script runs the browser. If a new tab is already open, the capslock key closes the tab instead.
When attempting to run this script in AHK 2.0, I receive a syntax error right in the beginning (SetTitleMatchMode, 2). The error messages says something vague about parentheses and commas, but after reading through the update notes from 1.1 to 2.0, it is not clear to me what needs to be changed.
Error: Function calls require a space or "(". Use comma only between parameters.
Text: SetTitleMatchMode, 2
Line: 3
in v2 there are no longer any commands, just functions(although, in this case ure afforded a function call statement which u can read more about in the v2 docs)
the fix is
Error: Hotkey or hotstring is missing its opening brace.
Line: 3
in v2, for multi-line hotkeys/hotstrings, their subroutines are unnamed functions(a similar usage was already possible in v1, except with named functions). so u need to add braces in to delineate the function's body:
Error: Function calls require a space or "(". Use comma only between parameters.
Text: WinActivate, ahk_exe [browser].exe
Text: wingettitle, currentwindowtitle, ahk_exe [browser].exe
unquoted string literals generally no longer exist in v2(except for a few directives which still allow them), so Send's parameter needs to be a quoted string literal
Warning: This variable appears to never be assigned a value.
Specifically: local ahk_exe
004: If WinExist("ahk_exe [browser].exe")
006: {
▶ 007: WinActivate(ahk_exe [browser].exe)
008: wingettitle(currentwindowtitle, ahk_exe [browser].exe)
009: {
luckily, u already know what to do with unquoted string literals
the next error is
Warning: This variable appears to never be assigned a value.
Specifically: local currentwindowtitle
006: {
007: WinActivate('ahk_exe [browser].exe')
▶ 008: wingettitle(currentwindowtitle, ahk_exe [browser].exe)
009: {
010: If InStr(currentwindowtitle, '[New Page Title]')
here u need to check the WinGetTitle docs since the param order is different. generally, u will find fewer functions rely on OutputVar outparams(unless theyre returning more than 1 thing). and also u need to do something about that unquoted string literal there
Warning: This variable appears to never be assigned a value.
Specifically: local ahk_exe
026: Run("[browser location]")
027: sleep(100)
▶ 028: WinActivate(ahk_exe [browser].exe)
029: Send('^l')
030: }
which u already know how to fix
congratulations, ur first working v2 script