run Microsoft apps from the Microsoft store Topic is solved

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
User avatar
entropy
Posts: 93
Joined: 17 Oct 2014, 01:45

run Microsoft apps from the Microsoft store

Post by entropy » 26 Mar 2023, 07:53

Hello,

I’m trying to assign keyboard shortcuts to run Microsoft applications (from the store downloaded), for example WhatsApp, which is now a Microsoft Store application and not a standalone installation as it was previously.

But there is no way to find a way to start it with a keyboard shortcut other than clicking on its icon from the start menu.

This is the location where it’s installed C:\PROGRAM FILES\WINDOWSAPPS\5319275A.WHATSAPPDESKTOP_2.2310.3.0_X64__CV1G1GVANYJGM yet the exe which resides there doesn’t run!
Run "WhatsApp" does also nothing although in the past I could run it with this command.

Thanks

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

Re: run Microsoft apps from the Microsoft store  Topic is solved

Post by mikeyww » 26 Mar 2023, 08:02

viewtopic.php?p=438517#p438517

Code: Select all

; This script runs an app installed from the Microsoft Store
#Requires AutoHotkey v2.0

F3::SoundBeep(1500), runApp('WhatsApp')

runApp(appName) { ; https://www.autohotkey.com/boards/viewtopic.php?p=438517#p438517
 For app in ComObject('Shell.Application').NameSpace('shell:AppsFolder').Items
  (app.Name = appName) && RunWait('explorer shell:appsFolder\' app.Path)
}

User avatar
entropy
Posts: 93
Joined: 17 Oct 2014, 01:45

Re: run Microsoft apps from the Microsoft store

Post by entropy » 26 Mar 2023, 08:23

Thanks for answering but this code is far too advanced for my knowledge to edit it properly and adjust it.
I guessed that by changing the appName to WhatsApp and entering the path in the section app.Path : "" it would work but it doesn’t.
If you could adjust it for me, I’d appreciate it.
Thanks

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

Re: run Microsoft apps from the Microsoft store

Post by mikeyww » 26 Mar 2023, 08:37

Sure.
1. Run script.
2. Press F3.

User avatar
entropy
Posts: 93
Joined: 17 Oct 2014, 01:45

Re: run Microsoft apps from the Microsoft store

Post by entropy » 26 Mar 2023, 08:49

mikeyww wrote:
26 Mar 2023, 08:37
Sure.
1. Run script.
2. Press F3.
I have no words to thank you not only for this code but for all questions I posted, and you promptly answered.

The below is working perfectly now thanks to you.

Code: Select all

#+w::
{ ; WhatsApp
If WinExist("ahk_class ApplicationFrameWindow")
   If WinActive()
      WinMinimize
   Else WinActivate
Else
   runApp('WhatsApp')
   runApp(appName) {
 For app in ComObject('Shell.Application').NameSpace('shell:AppsFolder').Items
  (app.Name = appName) && RunWait('explorer shell:appsFolder\' app.Path)
}
}

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

Re: run Microsoft apps from the Microsoft store

Post by mikeyww » 26 Mar 2023, 09:14

You are welcome. A suggestion is below.

Code: Select all

#Requires AutoHotkey v2.0

#+w:: {  ; WIN-SHIFT-w = WhatsApp
 If WinExist("WhatsApp ahk_class ApplicationFrameWindow")
  If WinActive()
   WinMinimize(), MouseGetPos(,, &hWnd), WinActivate(hWnd)
  Else WinActivate
 Else runApp('WhatsApp')
}

runApp(appName) {
 For app in ComObject('Shell.Application').NameSpace('shell:AppsFolder').Items
  (app.Name = appName) && RunWait('explorer shell:appsFolder\' app.Path)
}

User avatar
entropy
Posts: 93
Joined: 17 Oct 2014, 01:45

Re: run Microsoft apps from the Microsoft store

Post by entropy » 26 Mar 2023, 09:28

Thanks!
It produces the same result.
What’s the difference? I see the MouseGetPos parameter. If I knew what this is for, I would most probably adjust also the scripts that are running the same code for other apps

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

Re: run Microsoft apps from the Microsoft store

Post by mikeyww » 26 Mar 2023, 09:42

The AHK documentation can help you understand any AHK function.

In some cases, minimizing a window does not inactivate it. The revised script will activate the window under the mouse.

You don't need to repeat the code. That is why functions can be created.

Code: Select all

#Requires AutoHotkey v2.0

#+w::toggleWindow('WhatsApp', 'WhatsApp ahk_class ApplicationFrameWindow')
F3::toggleWindow(A_WinDir '\System32\notepad.exe', 'ahk_exe notepad.exe')

toggleWindow(appNameOrPath, winTitle) {
 If WinExist(winTitle)
  If WinActive()
   WinMinimize(), MouseGetPos(,, &hWnd), WinActivate(hWnd)
  Else WinActivate
 Else runApp(appNameOrPath)
}

runApp(appNameOrPath) {
 If !FileExist(appNameOrPath) {
  For app in ComObject('Shell.Application').NameSpace('shell:AppsFolder').Items
   (app.Name = appNameOrPath) && RunWait('explorer shell:appsFolder\' app.Path)
 } Else Run(appNameOrPath)
}

User avatar
entropy
Posts: 93
Joined: 17 Oct 2014, 01:45

Re: run Microsoft apps from the Microsoft store

Post by entropy » 26 Mar 2023, 10:09

Oh! I do get the point now. However, with the previous code the window that was minimised was in all scenarios deactivated and the previous window was activated.
But I do see the point and I’ll go through the code you’ve posted to understand its functionality and use it.
Thank you again for your assistance!

wlashack
Posts: 39
Joined: 25 Aug 2019, 01:28

Re: run Microsoft apps from the Microsoft store

Post by wlashack » 28 Mar 2023, 10:29

Hello,
I am not a codie, I am only trying to find a solution of the same situation as described in this thread.
When I copy the code above to my AHK script and try tu run the script, it returns me error, where the "line 88" is the first line of the code copied from two posts above:
Image

What is wrong? Thanks!

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

Re: run Microsoft apps from the Microsoft store

Post by mikeyww » 28 Mar 2023, 10:45

Although the posted script works, and your script does not work, I do not have a magic ball to see what your script is! You could post it in a new reply below.

gregster
Posts: 8988
Joined: 30 Sep 2013, 06:48

Re: run Microsoft apps from the Microsoft store

Post by gregster » 28 Mar 2023, 10:49

@wlashack, based on your other recent post, it seems you are running AHK v1 (although posted in the v2 forum). The code above is AHK v2, though.

wlashack
Posts: 39
Joined: 25 Aug 2019, 01:28

Re: run Microsoft apps from the Microsoft store

Post by wlashack » 28 Mar 2023, 13:38

Oh my, you are absolutely right. Thanks for the info and sorry for the chaos I made here. Now I look into the help files and finding differences between v1 and v2 syntax etc.

On the other hand, maybe I found a more straightforward solution for launching WhatsApp from Microsoft Store. Here it is:

Code: Select all

#w::
{
Run "C:\Program Files\WindowsApps\5319275A.WhatsAppDesktop_2.2310.3.0_x64__cv1g1gvanyjgm\WhatsApp.exe"
}
It works for me pretty well in AHK v2.
Question is what happens when Whatsapp gets an update some day, maybe the link will have to change to another directory.

User avatar
boiler
Posts: 16900
Joined: 21 Dec 2014, 02:44

Re: run Microsoft apps from the Microsoft store

Post by boiler » 28 Mar 2023, 14:27

wlashack wrote: Question is what happens when Whatsapp gets an update some day, maybe the link will have to change to another directory.
This will handle changes to the sub-directory due to version updates:

Code: Select all

#w:: {
	loop Files, A_ProgramFiles "\WindowsApps\WhatsApp.exe", "R" {
		Run '"' A_LoopFileFullPath '"' ; best to surround it in quotes in case there are spaces in the path
		break
	}
}

wlashack
Posts: 39
Joined: 25 Aug 2019, 01:28

Re: run Microsoft apps from the Microsoft store

Post by wlashack » 28 Mar 2023, 14:34

Hmm, looks like it does not work for me.
Last edited by wlashack on 28 Mar 2023, 14:35, edited 1 time in total.

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

Re: run Microsoft apps from the Microsoft store

Post by mikeyww » 28 Mar 2023, 14:35

Or:

Code: Select all

#Requires AutoHotkey v1.1.33

F3::runApp("WhatsApp")
F4::runApp(A_WinDir "\System32\notepad.exe")

runApp(appNameOrPath) {
 If !FileExist(appNameOrPath) {
  For app in ComObjCreate("Shell.Application").NameSpace("shell:AppsFolder").Items
   If (app.Name = appNameOrPath)
    RunWait % "explorer shell:appsFolder\" app.Path
 } Else Run % appNameOrPath
}

User avatar
boiler
Posts: 16900
Joined: 21 Dec 2014, 02:44

Re: run Microsoft apps from the Microsoft store

Post by boiler » 28 Mar 2023, 14:37

wlashack wrote: Hmm, looks like it does not work for me.
That exact script works for me when I change it for an app I have. That was a v2 script, so to make sure you're running v2 when running that script, put this at the top:

Code: Select all

#Requires AutoHotkey v2.0

If it still doesn't work, did you copy, paste, and run it exactly as I posted it, or did you change what you thought needed to be changed by inspection? Did you remember to press the hotkey? What does it show if you run this version?

Code: Select all

#Requires AutoHotkey v2.0
#w:: {
	loop Files, A_ProgramFiles "\WindowsApps\WhatsApp.exe", "R" {
		MsgBox '"' A_LoopFileFullPath '"'
		break
	}
}

wlashack
Posts: 39
Joined: 25 Aug 2019, 01:28

Re: run Microsoft apps from the Microsoft store

Post by wlashack » 29 Mar 2023, 14:31

I use the script the exact way it is written here in the latest post above, did not change anything:

Code: Select all

#Requires AutoHotkey v2.0
#w:: {
	loop Files, A_ProgramFiles "\WindowsApps\WhatsApp.exe", "R" {
		MsgBox '"' A_LoopFileFullPath '"'
		break
	}
}

After pressing Win+W shortuct, nothing happens.

The path to WhatsApp.exe on my Win11 laptop is:

Code: Select all

"C:\Program Files\WindowsApps\5319275A.WhatsAppDesktop_2.2311.3.0_x64__cv1g1gvanyjgm\WhatsApp.exe"
One possible cause of the problem that comes to my mind is that WindowsApps directory is hidden and can be achieved by admin only. Maybe?

User avatar
boiler
Posts: 16900
Joined: 21 Dec 2014, 02:44

Re: run Microsoft apps from the Microsoft store

Post by boiler » 29 Mar 2023, 14:42

wlashack wrote: One possible cause of the problem that comes to my mind is that WindowsApps directory is hidden and can be achieved by admin only. Maybe?
Possibly. Try the version below and see if it displays "C:\Program Files\AutoHotkey\UX\ui-dash.ahk", assuming that's where you have AHK installed.

Code: Select all

#Requires AutoHotkey v2.0
#w:: {
	loop Files, A_ProgramFiles "\AutoHotkey\ui-dash.ahk", "R" {
		MsgBox '"' A_LoopFileFullPath '"'
		break
	}
}

Note that it finds and displays the full path to the file even though the subfolder UX wasn't in the loop path.

wlashack
Posts: 39
Joined: 25 Aug 2019, 01:28

Re: run Microsoft apps from the Microsoft store

Post by wlashack » 29 Mar 2023, 14:47

Yes, it returns me a message box with the path after pressing Win+w shortcut.

Post Reply

Return to “Ask for Help (v2)”