StrokesPlus.net
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
Nsc  
#1 Posted : Friday, November 22, 2019 2:23:12 AM(UTC)
Nsc

Rank: Newbie

Reputation:

Groups: Approved
Joined: 11/6/2019(UTC)
Posts: 8

Thanks: 3 times
Hello

I want to open UWP applications in Windows10 with strokesplus.net,
for example: the Windows Calculator.

But I don't know how.
Could you please tell me how to open it?

Thank you!

Nsc
Rob  
#2 Posted : Friday, November 22, 2019 3:32:41 AM(UTC)
Rob

Rank: Administration

Reputation:

Groups: Translators, Members, Administrators
Joined: 1/11/2018(UTC)
Posts: 1,349
United States
Location: Tampa, FL

Thanks: 28 times
Was thanked: 416 time(s) in 354 post(s)
This works for me:
Code:
sp.RunProgram("calc", "", "open", "normal", true, false, false);
thanks 1 user thanked Rob for this useful post.
Nsc on 11/22/2019(UTC)
Rob  
#3 Posted : Friday, November 22, 2019 3:53:29 AM(UTC)
Rob

Rank: Administration

Reputation:

Groups: Translators, Members, Administrators
Joined: 1/11/2018(UTC)
Posts: 1,349
United States
Location: Tampa, FL

Thanks: 28 times
Was thanked: 416 time(s) in 354 post(s)
It's been long overdue to make a simpler run command, so I've added a new function in 0.3.5.9:
Code:
sp.Run("calc");

Edited by user Friday, November 22, 2019 3:54:02 AM(UTC)  | Reason: Not specified

thanks 1 user thanked Rob for this useful post.
Humphries on 8/29/2020(UTC)
Nsc  
#4 Posted : Friday, November 22, 2019 7:57:38 AM(UTC)
Nsc

Rank: Newbie

Reputation:

Groups: Approved
Joined: 11/6/2019(UTC)
Posts: 8

Thanks: 3 times
Rob

Thank you very much for your reply.
This works on my PC too.
Code:
sp.RunProgram("calc", "", "open", "normal", true, false, false);


And Thank you for adding this new wonderful function in the next version.
Code:
sp.Run("calc");


But I have a list of other applications to set, and not all of them works well in the way above.
In order to open that UWP applications, I need a universal way.

Is there an universal way that I can use it to open any UWP Apps with strokesplus.net?
For example open the UWP version of 'Inkscape'.
(And of course I have a lot of other UWP Apps to set.)

Nsc
Rob  
#5 Posted : Friday, November 22, 2019 10:41:45 AM(UTC)
Rob

Rank: Administration

Reputation:

Groups: Translators, Members, Administrators
Joined: 1/11/2018(UTC)
Posts: 1,349
United States
Location: Tampa, FL

Thanks: 28 times
Was thanked: 416 time(s) in 354 post(s)
The universal way is to run the applications by their path and executable name.

There's no built-in function to somehow take a program's name and find its path/exe for you. I might look into something to make it easier, but I have a feeling it might be complicated based on many factors.

So just right-click the app's shortcut on the Start menu and get the properties/file location.
thanks 1 user thanked Rob for this useful post.
Nsc on 11/23/2019(UTC)
Nsc  
#6 Posted : Saturday, November 23, 2019 12:45:43 PM(UTC)
Nsc

Rank: Newbie

Reputation:

Groups: Approved
Joined: 11/6/2019(UTC)
Posts: 8

Thanks: 3 times
Originally Posted by: Rob Go to Quoted Post
The universal way is to run the applications by their path and executable name.

There's no built-in function to somehow take a program's name and find its path/exe for you. I might look into something to make it easier, but I have a feeling it might be complicated based on many factors.

So just right-click the app's shortcut on the Start menu and get the properties/file location.


Rob

Thank you for your reply.

It is not easy to get an UWP app's location.
Because in the UWP app's context menu there is no properties/file location.
Maybe Because that location is not accessable.

But finally I found a way to open them.
It is like this: (take the Calculator as example)
Code:
sp.RunProgram(sp.ExpandEnvironmentVariables("%SystemRoot%")+"\\explorer.exe", "shell:appsFolder\\Microsoft.WindowsCalculator_8wekyb3d8bbwe!App", "", "", false, false, false);


I found this way when I saw this:
how to open an UWP app from the command line

The way to open an UWP app from the command line is like this:
Code:
explorer.exe shell:appsFolder\PackageFamilyName!Application ID


So in strokesplus.net just open "explorer.exe" and set the parameter as "shell:appsFolder\\PackageFamilyName!Application ID"
I tried that way and it works.

Maybe this is the best way I can found to open an UWP app so far.

Nsc
Rob  
#7 Posted : Saturday, November 23, 2019 5:43:35 PM(UTC)
Rob

Rank: Administration

Reputation:

Groups: Translators, Members, Administrators
Joined: 1/11/2018(UTC)
Posts: 1,349
United States
Location: Tampa, FL

Thanks: 28 times
Was thanked: 416 time(s) in 354 post(s)
Ah I see, I've never tried to work with UWP apps in this way.

Here's a script that will let you search for apps to get their full execution string (copied to the clipboard) using PowerShell and piping the output into a variable, it also starts the app.

If there's only one match, it simply starts the app. If multiple matches were found it presents a list to choose from.

I haven't tested it extensively, but it seems to work okay for the few things I've tried. It could probably be improved upon, just threw it together quickly.

Code:
var searchInputBoxInfo = new InputBoxInfo();
searchInputBoxInfo.Title = 'Search For UWP App';
searchInputBoxInfo.Message = 'Enter a partial name of the UWP app to locate.';
searchInputBoxInfo.AllowDirectInput = true;
searchInputBoxInfo.ShowAtMouseCursor = true;
var searchString = sp.InputBox(searchInputBoxInfo);

if(searchString != null) {
    var p = new clr.System.Diagnostics.Process();
    p.StartInfo.UseShellExecute = false;
    p.StartInfo.RedirectStandardOutput = true;
    p.StartInfo.FileName = "PowerShell.exe";
    p.StartInfo.CreateNoWindow = true;
    p.StartInfo.Arguments = "-command get-appxpackage"
    p.Start();
    var output = p.StandardOutput.ReadToEnd();
    p.WaitForExit();

    var arrayOfLines = output.match(/[^\r\n]+/g);
    var inputBoxInfo = new InputBoxInfo();
    inputBoxInfo.Title = 'Select UWP App';
    inputBoxInfo.Message = 'Select a UWP app below and click OK to activate it.';

    for(var i = 0; i < arrayOfLines.length - 1;i++) {
        if(arrayOfLines[i].indexOf("PackageFamilyName : ") > - 1) {
            var appPackageFam = arrayOfLines[i].replace("PackageFamilyName : ", "") ;
            if(appPackageFam.toLowerCase().indexOf(searchString.toLowerCase()) > -1) {
                inputBoxInfo.Items.Add(appPackageFam + "!App");        
            }
        }
    }

    inputBoxInfo.AllowDirectInput = false;
    inputBoxInfo.Sort = true;
    inputBoxInfo.ShowAtMouseCursor = true;

    var appName = "";
    if(inputBoxInfo.Items.Count ==  1) {
        //Only one match found, so just start it
        appName = inputBoxInfo.Items[0];
    } else {
        //Show list of potential apps matched
        var res = sp.InputBox(inputBoxInfo);
        if(res != null) {
            appName = res;
        } else {
            appName = "";
        }
    }

    if(appName != "") {
        //This line copies the full S+ run command for the selected app
        //so you can use it directly for much faster opening without searching
        clip.SetText(`sp.RunProgram(sp.ExpandEnvironmentVariables("%SystemRoot%")+"\\\\explorer.exe", "shell:appsFolder\\\\${appName}", "", "", false, false, false);`);

        //Start the app
        sp.RunProgram(sp.ExpandEnvironmentVariables("%SystemRoot%")+"\\explorer.exe", "shell:appsFolder\\"+appName, "", "", false, false, false);
    }
}

Edited by user Saturday, November 23, 2019 5:49:00 PM(UTC)  | Reason: Not specified

Nsc  
#8 Posted : Sunday, November 24, 2019 5:50:22 AM(UTC)
Nsc

Rank: Newbie

Reputation:

Groups: Approved
Joined: 11/6/2019(UTC)
Posts: 8

Thanks: 3 times
It works.

But when no matches were found, it also presents a empty list.
So I add an if before line 38:
Code:
if (inputBoxInfo.Items.Count ==  0) {
        sp.MessageBox("No App Matches!", "No App Matches!");
    }

Maybe it's better to back to search, but I don't know how.
Rob  
#9 Posted : Sunday, November 24, 2019 3:02:12 PM(UTC)
Rob

Rank: Administration

Reputation:

Groups: Translators, Members, Administrators
Joined: 1/11/2018(UTC)
Posts: 1,349
United States
Location: Tampa, FL

Thanks: 28 times
Was thanked: 416 time(s) in 354 post(s)
This will create a loop to keep trying if no matches are found, or will exit if you click Cancel at the search dialog.

Code:
//Used to control loop, to keep trying if no match found
var keepTrying = true;
var searchMessage = 'Enter a partial name of the UWP app to locate.';

while (keepTrying) {
    var searchInputBoxInfo = new InputBoxInfo();
    searchInputBoxInfo.Title = 'Search For UWP App';
    searchInputBoxInfo.Message =  searchMessage;
    searchInputBoxInfo.AllowDirectInput = true;
    searchInputBoxInfo.ShowAtMouseCursor = true;
    var searchString = sp.InputBox(searchInputBoxInfo);

    if(searchString != null) {
        var p = new clr.System.Diagnostics.Process();
        p.StartInfo.UseShellExecute = false;
        p.StartInfo.RedirectStandardOutput = true;
        p.StartInfo.FileName = "PowerShell.exe";
        p.StartInfo.CreateNoWindow = true;
        p.StartInfo.Arguments = "-command get-appxpackage"
        p.Start();
        var output = p.StandardOutput.ReadToEnd();
        p.WaitForExit();

        var arrayOfLines = output.match(/[^\r\n]+/g);
        var inputBoxInfo = new InputBoxInfo();
        inputBoxInfo.Title = 'Select UWP App';
        inputBoxInfo.Message = 'Select a UWP app below and click OK to activate it.';

        for(var i = 0; i < arrayOfLines.length - 1;i++) {
            if(arrayOfLines[i].indexOf("PackageFamilyName : ") > - 1) {
                var appPackageFam = arrayOfLines[i].replace("PackageFamilyName : ", "") ;
                if(appPackageFam.toLowerCase().indexOf(searchString.toLowerCase()) > -1) {
                    inputBoxInfo.Items.Add(appPackageFam + "!App");        
                }
            }
        }

        inputBoxInfo.AllowDirectInput = false;
        inputBoxInfo.Sort = true;
        inputBoxInfo.ShowAtMouseCursor = true;

        if(inputBoxInfo.Items.Count > 0) {
            var appName = "";
            if(inputBoxInfo.Items.Count ==  1) {
                //Only one match found, so just start it
                appName = inputBoxInfo.Items[0];
            } else {
                //Show list of potential apps matched
                var res = sp.InputBox(inputBoxInfo);
                if(res != null) {
                    appName = res;
                } else {
                    appName = "";
                }
            }

            if(appName != "") {
                //App selected, so exit loop
                keepTrying = false;
            
                //This line copies the full S+ run command for the selected app
                //so you can use it directly for much faster opening without searching
                clip.SetText(`sp.RunProgram(sp.ExpandEnvironmentVariables("%SystemRoot%")+"\\\\explorer.exe", "shell:appsFolder\\\\${appName}", "", "", false, false, false);`);

                //Start the app
                sp.RunProgram(sp.ExpandEnvironmentVariables("%SystemRoot%")+"\\explorer.exe", "shell:appsFolder\\"+appName, "", "", false, false, false);
            }
        } else {
            //No matches found, try search again
            searchMessage = 'No matches found. Try again or click Cancel to exit script.';
        }
    } else {
        //Clicked Cancel in the search text popup window, so exit script
        keepTrying = false;
    }
}
Nsc  
#10 Posted : Sunday, November 24, 2019 3:40:40 PM(UTC)
Nsc

Rank: Newbie

Reputation:

Groups: Approved
Joined: 11/6/2019(UTC)
Posts: 8

Thanks: 3 times
It works well. Thank you! Rob.
Users browsing this topic
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.