Start Outlook minimized Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
RDC
Posts: 112
Joined: 29 Jan 2023, 10:22

Start Outlook minimized

Post by RDC » 29 Jan 2023, 11:02

I really hope someone can help this AHK extreme noob..

I am trying to create a script to simply start Outlook minimized that I can drop in the startup folder.
What I've got so far opens Outlook, but as a greyed out generic looking version that doesn't have both my email accounts
... and starts maximized. I've attached images of the good version vs the bad (greyed out) as example.

Code: Select all

; Start Outlook minimized.
#SingleInstance Ignore
F12::Run, Outlook, "C:\Program Files\Microsoft Office\root\Office16\OUTLOOK.EXE", Min
return
Esc::ExitApp
image.png
image.png (977.82 KiB) Viewed 951 times


Would really appreciate any guidance on this. Thank you!

User avatar
mikeyww
Posts: 26937
Joined: 09 Sep 2014, 18:38

Re: Start Outlook minimized

Post by mikeyww » 29 Jan 2023, 11:23

Welcome to this AutoHotkey forum!

See documentation for the correct syntax.

Code: Select all

Run, Target [, WorkingDir, Options, OutputVarPID]

Code: Select all

; Start Outlook minimized
#Requires AutoHotkey v1.1.33
F12::
Run % A_ProgramFiles "\Microsoft Office\root\Office16\OUTLOOK.EXE"
SoundBeep 1500
WinWait ahk_exe OUTLOOK.EXE,, 9, Opening
If !ErrorLevel {
 Sleep 500
 WinMaximize
 WinMinimize
}
Return

Code: Select all

; Start Outlook minimized
#Requires AutoHotkey v2.0
appPath := (pName) => RegRead('HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\'
                            . pName)

F12:: {
 Static outlook := 'OUTLOOK.exe'
 Run appPath(outlook)
 SoundBeep 1500
 If WinWait('ahk_exe' outlook,, 9, 'Opening') {
  Sleep 500
  WinMaximize
  WinMinimize
 }
}
Last edited by mikeyww on 29 Jan 2023, 11:37, edited 2 times in total.

User avatar
RDC
Posts: 112
Joined: 29 Jan 2023, 10:22

Re: Start Outlook minimized

Post by RDC » 29 Jan 2023, 11:33

Many thanks for the extremely quick reply!!
It works as I was hoping except it's opening the greyed out version. I'm thinking I need to figure out exactly what it is opening.
The good version looks more like an app while the bad one looks like it is a very old version with only the hotmail account attached.
I think if I can determine that this will work perfect. So once again, many many thanks!!!

User avatar
mikeyww
Posts: 26937
Joined: 09 Sep 2014, 18:38

Re: Start Outlook minimized

Post by mikeyww » 29 Jan 2023, 11:41

In some cases, programs require a working directory or "Start in" directory to be specified. As noted above, you can specify such a directory in the second parameter of the Run command, though I have never found that it is needed for Microsoft Outlook. In any case, the solution should be evident if you examine how you normally run Outlook without your script. If you are running the script as admin, you may get unexpected results.

User avatar
RDC
Posts: 112
Joined: 29 Jan 2023, 10:22

Re: Start Outlook minimized

Post by RDC » 29 Jan 2023, 13:28

So while your script worked well, it kept opening a greyed version. Turns out this is apparently because Windows 10 goes through apps.
Source: https://answers.microsoft.com/en-us/windows/forum/all/how-to-make-mail-app-open-automatically-upon/64b1e95a-f1b6-435e-98d4-ca50340db88b
So I edited your code to change the Run line base on the new known location and while that opens my Outlook in the colored version, it now does not minimize...
Any further suggestions? I've a feeling it may be the new entry for WinWait, but don't understand what is wrong. Thank you again

Code: Select all

; Start Outlook Minimized
#Requires AutoHotkey v1.1.33
F12::
Run % A_explorer "shell:AppsFolder\microsoft.windowscommunicationsapps_8wekyb3d8bbwe!microsoft.windowslive.mail"
SoundBeep 1500
WinWait ahk_exe microsoft.windowslive.mail,, 9, Opening
If !ErrorLevel {
 Sleep 500
 WinMaximize
 WinMinimize
}
Return

[Mod edit: Added [code][/code] tags. Please use them yourself when posting code.]

User avatar
mikeyww
Posts: 26937
Joined: 09 Sep 2014, 18:38

Re: Start Outlook minimized  Topic is solved

Post by mikeyww » 29 Jan 2023, 14:08

If you run Window Spy and then activate the Outlook window, you will be able to see the WinTitle information (e.g., window class or process name) for that window. You can then specify it.

Your current WinTitle is incorrect, as all process names end in .exe.

User avatar
RDC
Posts: 112
Joined: 29 Jan 2023, 10:22

Re: Start Outlook minimized

Post by RDC » 29 Jan 2023, 14:24

Once again, I thank you sir!!
Final result after your Window Spy suggestion... Works AWESOME!! :superhappy:

Final code...

Code: Select all

; Start Outlook minimized
#Requires AutoHotkey v1.1.33
#SingleInstance Ignore
Run % A_explorer "shell:AppsFolder\microsoft.windowscommunicationsapps_8wekyb3d8bbwe!microsoft.windowslive.mail"
SoundBeep 2200
WinWait ahk_exe ApplicationFrameHost.exe,, 9, Opening
If !ErrorLevel {
 Sleep 550
 WinMaximize
 WinMinimize
}
Return
ExitApp

User avatar
mikeyww
Posts: 26937
Joined: 09 Sep 2014, 18:38

Re: Start Outlook minimized

Post by mikeyww » 29 Jan 2023, 16:37

Looks nice.

ExitApp will never execute, because Return precedes it. Nonetheless, for non-persistent scripts, Return at the script's top level will exit the script.

Explained: Return
If there is no caller to which to return, Return will do an Exit instead.

User avatar
flyingDman
Posts: 2817
Joined: 29 Sep 2013, 19:01

Re: Start Outlook minimized

Post by flyingDman » 29 Jan 2023, 21:32

COM might be a better alternative. Try:

Code: Select all

F12::
ol := ComObjCreate("outlook.application")
ol.Session.GetDefaultFolder(6).Display	; https://learn.microsoft.com/en-us/office/vba/api/outlook.oldefaultfolders
ol.ActiveWindow.WindowState := 1
return
The Window still shows but minimizes very quickly. No sleeps or winwaits necessary.
14.3 & 1.3.7

User avatar
RDC
Posts: 112
Joined: 29 Jan 2023, 10:22

Re: Start Outlook minimized

Post by RDC » 30 Jan 2023, 08:53

Wow, thank you for this. It works really well. One problem it loads and minimizes, but not to the system try.
It just sits in the center of the screen 1/2 sized. Is there anything I could alter to get it to the system tray?
Looks like I'm going to have to study COM some as it looks cleaner and in appearance seems to do a lot of the work itself.

Many thanks in advance!!

User avatar
flyingDman
Posts: 2817
Joined: 29 Sep 2013, 19:01

Re: Start Outlook minimized

Post by flyingDman » 30 Jan 2023, 11:12

ol.ActiveWindow.WindowState := 1 should minimize the Outlook window. 0 should maximize it and 2 should return it to its normal state. It works as expected here. Make sure other instances of Outlook are closed.
14.3 & 1.3.7

User avatar
RDC
Posts: 112
Joined: 29 Jan 2023, 10:22

Re: Start Outlook minimized

Post by RDC » 30 Jan 2023, 11:27

Thank you for the clarification. Your script works perfectly as advertised. Turns out it works exactly as described on my desktop, but was trying to use it with my work from home laptop.
I have many programs I have to open and work with so am attempting to streamline/automate my startup time.
As it still works, although without sending to the taskbar on the WFH laptop, I'm assuming it's some of the work software preventing the full desired affect.
But it does still work great so will keep this. Now to figure out how to automate the startup of a few rdp programs.
Thank you guys so much for getting me pointed in the right direction!! I'm realizing it will take more than a couple weekends for me to learn this stuff enough to be proficient.

User avatar
mikeyww
Posts: 26937
Joined: 09 Sep 2014, 18:38

Re: Start Outlook minimized

Post by mikeyww » 30 Jan 2023, 11:49

Well, I don't know, 96 hours is time to learn a lot.

:)

User avatar
RDC
Posts: 112
Joined: 29 Jan 2023, 10:22

Re: Start Outlook minimized

Post by RDC » 30 Jan 2023, 11:56

:HeHe: I'll see what I can do... lol.

Post Reply

Return to “Ask for Help (v1)”