0
votes

I am trying to make a basic shortcut for windowsHome + Shift + w. If word is open, I would like to set Word as the active window and maximize Word; else, if word isn't open, I would like to open a specified word document. This script works fine running once but can't run multiple times without restarting the script. I tried adding #Persistent and a never-ending while loop but this still doesn't work. What I am doing wrong? Thank you for your help in advance! I will definitely rate you up if you help me out.

 #Persistent
 #NoEnv
 #Warn  
 SendMode Input
 SetWorkingDir %A_ScriptDir%
 #+w::  
 while 1
 {
  IfWinExist *.docx - Microsoft Word
  {
    WinActivate
    WinMaximize
  }
  else
  {
      Run, C:\Users\myHome\Desktop\311.docx
  }
}
return 
1

1 Answers

2
votes

This is working for me:

SendMode Input
SetWorkingDir %A_ScriptDir%
#+w::
  IfWinExist ahk_class OpusApp
  {
    WinActivate ahk_class OpusApp
    WinMaximize ahk_class OpusApp
  }
  else
  {
      Run, C:\Users\myHome\Desktop\311.docx
      WinWait ahk_class OpusApp
      WinActivate ahk_class OpusApp
  }
return 

I highly recommend using the ahk_class for this purpose.

Also, you don't need the loop, otherwise it will consistently loop after the keys are pressed, keeping the window maximized. In this example, the actions happen after the keys are pressed, but only happen once.

Also, the ahk_class OpusApp is the correct class for Microsoft Word 2010.

Let me know if you need any more help.