AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Convenient app-launching function

 
Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
kobyashi



Joined: 09 May 2005
Posts: 7

PostPosted: Sat May 14, 2005 9:21 pm    Post subject: Convenient app-launching function Reply with quote

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
Back to top
View user's profile Send private message
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10716

PostPosted: Sat May 14, 2005 9:28 pm    Post subject: Reply with quote

Looks useful. Thanks for posting it.
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group