kobyashi
Joined: 09 May 2005 Posts: 7
|
Posted: Sat May 14, 2005 9:21 pm Post subject: Convenient app-launching function |
|
|
Thanks to Chris for adding functions!
Below is some of the code I'm using in my AutoHotkey.ini. I think organizing the code this way makes it very readable and easily adjustable for other users' purposes. On top are some hotkeys which rely on code later in the file. The main thing I'm demonstrating here is the function RunRestoreHideApp which does like it says: runs an app that doesn' t already have an instance, barring that, finds the instance and either activates it, or if already active, minimizes it. Note the function returns what it actually did to the app. My #s macro launches a "sponsor-ware" app, then kills the nag message.
| Code: | #g::RunRestoreHideApp("Microsoft Visual","C:\Program Files\Microsoft Visual Studio .NET 2003\Common7\IDE\devenv.exe") ; goto RunRestoreVS
#a::RunRestoreHideApp2("Microsoft Outlook","Outlook","Microsoft Office Outlook")
^!a::goto HideAIM
#z:: run, "c:\Program Files\Autohotkey\fw", "c:\Program Files\Autohotkey"
^!n::RunRestoreHideApp("Notepad","Notepad")
#s::
if RunRestoreHideApp("Yahoo! All-Seeing Eye","C:\Program Files\The All-Seeing Eye\eye.exe") = ran
{
WinWaitActive, Invalid code, ,5
Sleep, 0
Send, {tab}{space} ; click "no"
}
return
;//////////////// Control Media Player //////////////////////////////////
^+c::
IfWinExist, Windows Media Player
ControlSend, ahk_parent, ^p
return
^+v::
IfWinExist, Windows Media Player
ControlSend, ahk_parent, ^f
return
KillActive:
WinGet, pid, PID , A
if (pid)
Process, Close, %pid%
;WinKill, A
return
RunRestoreHideApp2(title1, app, title2)
{
DetectHiddenWindows, On
SetTitleMatchMode, 2
app = "%app%"
If WinExist(title1) or (title2 <> "" and WinExist(title2))
{
IfWinActive
{
WinMinimize
return min
}
else
{
WinActivate
return act
}
}
else
{
Run, %app%
return ran
}
}
RunRestoreHideApp(title1, app)
{
RunRestoreHideApp2(title1, app, "")
}
HideAIM:
DetectHiddenWindows, On
SetTitleMatchMode, 2
IfWinExist, Default Away Message
{
WinActivate
;WinWaitActive
Send, {Enter}
}
else IfWinExist, Buddy List
{
;WinActivate
SendMessage, 0x111, 24003, 0
;WinMenuSelectItem, Buddy List,,My AIM,Away Message,Default Away Message
;MsgBox, Buddy
}
return
|
|
|