How To Start Windows Store Apps in AutoHotKey? - windows-10

Window Store apps are not like the classic Windows apps. The latter usually are installed at clear paths under C:\Program Files. So, AutoHotKey (AHK) scripts can simply run a classic app by "Run" with the path to the app executable. However, it seems there is no simple path to Windows Store app executables. So, how to start Windows Store apps in AutoHotKey scripts with a simple way?

Assume the OS is Windows 10. The following steps are a simple way to start Windows Store app in AHK script:
Create a folder, e.g. D:\WinStoreAppLinks
Drag and drop a Windows Store app, e.g. OneNote (mobile), by mouse in All App List to D:\WinStoreAppLinks (through File Explorer). It will create a link there, OneNote. You can rename it as you want.
The app can be run in AutoHotKey scripts (or Command Prompt), by e.g.:
Run, D:\WinStoreAppLinks\OneNote

Run shell:AppsFolder\Microsoft.WindowsAlarms_8wekyb3d8bbwe!App
Check shell:AppsFolder for full app names list

Here is a more verbose answer that worked for me:
In an Explorer window navigate to shell:AppsFolder. This is a directory with all your Windows apps
Find the app you want to launch (in my case Windows Terminal), right click it, and select Create Shortcut
Accept the prompt to create this shortcut on your desktop
Put this shortcut somewhere other than your desktop (e.g. C:\Shortcuts). Rename if desired
Add this to your AHK script:
Run, "C:\Shortcuts\Windows Terminal"
Then simple reload your AHK script. Enjoy

This autohotkey script https://github.com/JuanmaMenendez/AutoHotkey-script-Open-Show-Apps works perfectly with any kind of app.
In the specific case of Windows Store Apps, read the section Find AppUserModelID and use the Utility Function c)

Some of the other answers have the right idea, but are vague about which specific values to use or where to find them. Other answers have breaking typos. So here is an explanation of what you truly need, without requiring any additional shortcuts.
The Windows Store apps are in the Apps Folder, which you can see by entering shell:AppsFolder in the Win+R run window. The location identifier for the app is in the form: shell:AppsFolder\<PackageFamilyName>!<Name.id>, where <PackageFamilyName> and <Name.id> are placeholders. You'll need to replace those placeholders with the values for your application. For example, the location string for WhatsApp is shell:AppsFolder\5319275A.WhatsAppDesktop_cv1g1gvanyjgm!WhatsAppDesktop.
To discover the values for your application, go into PowerShell and look through the output of Get-AppxPackage to find the application you want. You can probably find it using: Get-AppxPackage -Name "*<AppName>*", substituting your own <AppName>. (Don't forget the asterisk wildcard.) The following will find WhatsApp, for example:
Get-AppxPackage -Name "*WhatsApp*"
If you still can't find it, enter the following in PowerShell and hit the spacebar to page through the output:
Get-AppxPackage * | more
Finally once you've formed the full application location identifier, use it in AutoHotkey like this:
Run "explorer.exe shell:AppsFolder\5319275A.WhatsAppDesktop_cv1g1gvanyjgm!WhatsAppDesktop"
Note that this uses the AutoHotkey v2 syntax.

Tested on 27.10.2020 (and works)
If you know turkish, check this site
You can use this powershell script to find the command of store apps
$appName = Read-Host "App name"
$installedapps = get-AppxPackage
foreach ($app in $installedapps)
{
foreach ($id in (Get-AppxPackageManifest $app).package.applications.application.id)
{
$line = $app.Name + " = " + $app.packagefamilyname + "!" + $id
if ($line.IndexOf($appName, [System.StringComparison]::CurrentCultureIgnoreCase) -ge 0) {
echo "shell:appsFolder\$app.packagefamilyname!$id"
}
}
}
To use it, first copy this script to notepad and select all recopy and paste to powershell console
Example output for WhatsApp:
shell:appsFolder\5319275A.WhatsAppDesktop_2.2041.7.0_x64__cv1g1gvanyjgm.packagefamilyname!WhatsAppDesktop
Finally copy these command and use in AHK like
Run explorer.exe "shell:appsFolder\5319275A.WhatsAppDesktop_2.2041.7.0_x64__cv1g1gvanyjgm.packagefamilyname!WhatsAppDesktop"
We need to copy to notepad to avoid powershell end of line issue (official bug) that makes line reserved

I just used my desktop shortcut (I couldn't find my system shortcut)
run C:\Users\YourUserName\Desktop\Minecraft Launcher.lnk

I noticed that I could launch an app with the Run command by typing its name. So for example, to launch a Windows Store app with spaces in its name, you could try something like:
Run, Files UWP - Preview
... where "Files UWP - Preview" could be any app's full name, as it is shown in the Start menu.
An advantage to this solution is that it doesn't rely on a shortcut that could potentially get deleted.

Related

How to find any app in our computer without typing the file location using python?

I am currently building an AI like google assistant. I want to open any app using python. How do I do that without typing the file location. Like we press the windows key and search our app, I mean like that.
I tried this:
import os
os.system("start ms-settings-DesiredApp:")
But this doesn't work for all apps.
I do not think is so easy. I mean I tried (on windows 10) to search different types of apps and I just finde some of the. That is because not all of them was installed.
Are some one file.exe what will work with out to install it (this type will not show on search bar)
Are some of them what are just an archive, and if is extracted will work fine (godot for the example: i get back just the archive name under folders tab)
And some of them have the option to not add folder on task bar and maybe for that reason some of the have no result in search bar
I do not know if is possible or impossible but maybe will not work like a quick search and you need to make another option to let the player/user to specifie where to search in case the file has not a start shortcut

Automate "Right-click + Print" on .xlsx files

I need to automate the act of printing .xlsx file.
I have already seen some answers to this task saying that it is possible by creating a VBA script, as well as some examples. That is not about what my question revolves around.
Thought, I know that it is also possible to right-click on a .xlsx file and click "Print", which does the exact task that I want. It opens Excel, prints the file to the default printer, then closes Excel. (Windows 7, by the way)
So I'm thinking that the work has already been done here.
What process is launched when clicking this "Print" option? Can it be launched via command line, or "clicked" by a python script or something? And if not, why? How can something so easy to click be impossible to automate? I assume a process of some sort must be launched in some way.
Found it!
This task can be easily launched using python.
import os
os.startfile('C:/path/to/the/file.xlsx','print')
This code will launch the same print task. From there, it is pretty trivial for a python developer to automate the task in his scripts.
However, if you do not know much about Python and do not want to learn it now, an easy (or lazy?) way to add it in any automation script would be to save the two lines of code above in a whatever.py file, and launch it via command line (with Python installed, of course).
The context menu print command for Office documents utilizes Dynamic Data Exchange (DDE) and does not directly run a command that can be replicated from the command line.
You can view the content of the commands in the registry. Browse to HKEY_CLASSES_ROOT\.xlsx and look at the (Default) data column. On my machine, "Excel.Sheet.12" is the type of a .xslx file. Then browse to HKEY_CLASSES_ROOT\Excel.Sheet.12\shell\ to see the commands registered for that file type. On my machine, the Print (Default) is "C:\Program Files\Microsoft Office\Office16\EXCEL.EXE" /dde and the "command" is zn=BV5!!!!4!!!!MKKSkEXCELFiles>]-z5hw$l[8QeZZR4_X=$ /dde, none of which is directly useful or accessible for running from a command line.
It will require another program to allow you to access the interface, but there are programs that allow you to make use of DDE from the command line. I recommend Freddy Vulto's Class Exec. More information and a few other similar utilities can be found here.

pywinauto (or others): to emulate Ctrl+A & Ctrl+X anywhere (not only on specified app)

I'm looking for a way to generate a ctrl+A (select all), and then ctrl+x in a python script. I know how to generate this in a specific app (pywinauto and other modules do that). But I'm looking for a way to send these keys in any apps (in any field of the active windows). I want to launch the python script containing these keys anywhere (the script will be launch using a key shortcut. Details below (1))
EDIT: I'm NOT trying to copy/past in the command windows (cf. the 2 last sentences). My script send the keys in the command windows, but that's the problem I'm trying to solve...
Using python pywinauto (or Ctypes or other modules)
I tried several propositions listed here with the same result.
I thought pywinauto could do it. Following pywinauto latest documentation I tried that:
open an (any) app containing a text field (that's the active windows)
place the cursor where you want to make the select all + cut/past
run the script bellow using an shortcut (so you won't leave the active windows)
from pywinauto.keyboard import SendKeys
SendKeys('^a^x')
Result
The code only print ^A^X in the python console. It doesn't do what it's suppose to do in the field of the active window (where I placed my cursor): it doesn't select all + cut the text.
Using autohotkey:
The only way I found to simulate a real crtl+A ctrl+C is by using autohotkey (it works but it's not a python solution):
save the code bellow in my AHK script: select_copy.ahk
Send, ^a
Send, ^x
create another AHK script called shortcut.ahk where you will specify a shortcut to launch select_copy.ahk (shortcut.ahk sould run constantly in windows background (2))
!^+G:: Run select_copy.ahk , C:\Users\Me\Desktop
(meaning: when I hit ctrl+alt+shift+G run the script select_copy.ahk)
result:
It works. when I call the ahk, it select/cut things in the active windows.
A combination of both did not work
I tried to launch the select_copy.ahk from within a python script (using subprocess.call) but I ended up with the same result than pywinauto (or Ctypes): it only prints ^A^X in the consol, but doesnt select&cut. So I'm wondering if python could really do what autohotkey does.
(1) What the script will do: I will launch the script (using a shortcut key) on one or another html editor, it will cut all the text, parse its source code, make some change put back the datas in the clipbboard, and past it. I'm only missing the first part (select all + cut) and the last part (past).
(2) It's not the big deal since shortcut.ahk contains also all my other ahk shortcuts and scripts.
Your AutoHotKey script should work, and does on my machine. However, I recommend that you just have one shortcut.ahk file containing the following:
!^+G::
Send, ^a
Send, ^x
Return
...and then put this in your python file:
subprocess.call("C:\\Path\\To\\AutoHotKey.exe /r C:\\Path\\To\\shortcut.ahk")
replacing the paths with wherever the AutoHotKey executable is, and wherever the shortcut.ahk file is.
Just as a side note: !^+G:: triggers on Alt+Shift+Ctrl+G, not Shift+Ctrl+G as you wrote in your question:
(meaning: when I hit ctrl+shift+G run the script select_copy.ahk)
EDIT: Also, from the phrase in the python console in your question it seems like you're trying to select all and then cut it in CMD. This will not work at all. Instead, if you want to simply clear the console, just use the command cls (Windows only; use clear in Linux). If you want to copy the entire console output and then clear it (i.e. cut) you're gonna need something different.

I've downloaded an .exe file but it closes quickly as it opens

I am trying to open a downloaded .exe file but it closes as soon as it opens. Is there any possible way so that I can open it for a longer duration to read the content.
It's probably a console application rather than a GUI application. Use the command prompt to run the .exe.
Do the following...
Hold down your Windows key on your keyboard and then tap "R".
This will bring up the Run dialog. Type in "cmd" (without the quotes). Hit enter.
(this will work in all Windows versions - browsing the start menu/screen differs in each version)
If you saved the file to c:\downloads and it's called myFile.exe, type
C:
cd C:\Downloads
myFile.exe
Some of the steps are a bit redundant - if you know what you're doing in the command prompt then skip as needed (but then you probably wouldn't be posting this question). This will work even if you saved the file to D:\downloads.
Another example - if you saved the file to D:\folderA\Folder with a space\ and the file is called "my file with a space.exe" then type
D:
cd "D:\folderA\Folder with a space"
"my file with a space.exe"
If there is an issue (eg it's a 64-bit executable and you're on 32-bit Windows) then you may get a better error message at the command line.
There are so many reasons why the executable does not run. Here are some ways to check what is going wrong:
Is it your .exe? Do you known the "normal" behavior?
When you download it manually, it the result the same?
Do you download the .exe manually or via your application?
Do you see any problem in your Windows Event Viewer?
Is it the same result if you try to download the .exe via different browsers (IE, FF, ...)?
More details are welcome!
The nuget.exe file is not a console GUI application but rather a console package. Once you've downloaded it, you'll want to place it in a folder outside your Downloads folder. For example, C:\NuGet\nuget.exe - then set it as a PATH variable so that it's executable from anywhere.

Is it possible to call an application selection window (Right click->Open With->Other) from the linux console?

On Gnome/KDE you can select in which application you want to open file (Right click on file -> Open With -> Other). Is it possible open file that way, but from console?
For example: you print " file.ext" and instead of opening in concrete application, there are that application selection window forced and then users chooses - starts selected program.
I tried to figure out that myself, but not found anything like that.
"edit file.ext" doesn't fits my needs, because it starts preferred application and you cannot choose which. And also on my desktop it says:
"Error: no "edit" mailcap rules found for type "image/jpeg"
So, am I able to forse that "open with" window from console? If yes, can you say how?
Both on windows and mac you can do such things.
//edit at 2009-02-10 14:17
Thank you very much for answers. Command will be used in program code, so unfortunately probably I would not be able to make some extra bash scripts.
For GNOME:
gnome-open <file>
For KDE:
kfmclient exec <file>
These commands should open up the <file> in the preferred application in GNOME or KDE respectively, although I don't have an installation of either to test on.
Take a look at man run-mailcap, you can change or add selected applications for each mimetype modifying the /etc/mailcap, ~/.mailcap files and some others.
Traditionally, on Unix systens (and therefore Linux, too), you start applications from the console (and not from a UI). The command line (or console) expects you to enter the name of the application and then the filename (plus some options).
This allows to use applications (or commands) in shell scripts.
On Windows, there is no real console (the DOS box is just a reminiscence of the dark ages of MS DOS). So the MS developers came up with the idea to have the OS treat anything as a command. If it's not a real command or application, the OS will determine the file type (by extension on Windows and by some header information on Mac). For each file type, there will be an associated application in a look up table.
This is why on Windows, it appears that you can enter the name of a file on the console and you will get the application to edit that file.
If you want a quick way to fix this in the Unix console, create a script called "open" or "o" and use the file command with the option --mime to identify the file type. You can then use a case statement to launch your favorite editor.
As for the error about "mailcap rules": There is a file called "mailcap" on Unix where you can define abstract "commands" (open, edit, view, print) for file types. See the mailcap man page.

Resources