Reputation: 3452
Hi everyone I am struggling with AutoHotKey and simple key binding.
What I am trying to achieve is that if ssms is not running, start it, otherwise set focus/active this program. At the moment I have something like this:
+!s::
StringCaseSense, On
process, exist, Ssms.exe
{
If !errorLevel
Run "C:\Program Files (x86)\Microsoft SQL Server\110\Tools\Binn\ManagementStudio\Ssms.exe"
else
IfWinExist Microsoft SQL Server Management Studio
WinActivate
}
This is working pretty fine until I create/open any SQL script in ssms. Any ideas how to fix this script?
Upvotes: 0
Views: 1298
Reputation: 6940
That code should work for you:
+!s::
StringCaseSense, On
Process, Exist, Ssms.exe
if ErrorLevel
{
IfWinExist, Microsoft SQL Server Management Studio
{
WinActivate
}
}
else
{
Run, C:\Program Files (x86)\Microsoft SQL Server\110\Tools\Binn\ManagementStudio\Ssms.exe
}
return
Here is also same code but for notepad.exe , which I have tested and it works fine:
+!s::
StringCaseSense, On
Process, Exist, notepad.exe
if ErrorLevel
{
IfWinExist, Untitled - Notepad
{
WinActivate
}
}
else
{
Run, c:\Windows\notepad.exe
}
return
Upvotes: 0
Reputation: 2999
This is a simplified version of what I use for all of my shortcuts. It uses a function (that can be reused). The first parameter is text in the window title. The second is the exe path.
SetTitleMatchMode, 2
+!s::ShowStart("Microsoft SQL Server Management Studio", "C:\Program Files (x86)\Microsoft SQL Server\110\Tools\Binn\ManagementStudio\Ssms.exe")
ShowStart(title, exe)
{
IfWinExist, %title%
WinActivate
else
{
Run, %exe%,, UseErrorLevel
If ErrorLevel
{
Msgbox, Exe not found.
Return
}
WinActivate
}
}
Upvotes: 2