Pin any executable to Start

Windows' Pin to Start function doesn't always work as expected: for example, you want to have your portable apps on the Start Menu but clicking Pin to Start doesn't do anything.

The manual solution for this is:

  1. Create a shortcut of the executable you want to pin in the /start\Programs (Opus will resolve this path to something like C:\Users\<Username>\AppData\Roaming\Microsoft\Windows\Start Menu\Programs for you automatically)
  2. The executable will now appear on the top of the "Recently added" list in your Start Menu.
  3. You can now right-click on it in the Start Menu and select "Pin to Start", and it will actually become pinned!

We can also create a context menu entry to partially automate this:
context_menu
Here's how to create the context menu entry for .exe files which will automate the step 1 for you:
a) Go to Settings > Preferences menu > File Types...
b) Find .exe entry and then in its "Context Menu" tab add a new "Standard Opus Function" and under "Action" give it a caption "Add to Start Menu" and as a code paste this:

Copy MAKELINK TO /start\Programs

(Note that you can do this for all files and folders, not necessarily just for .exe as in the example)

Now when you use this context menu action on the .exe files, the shortcut will be created in the Start for you, and you can simply follow the step 3 in the above manual instructions to pin the item on the Start menu!

2 Likes

Really like this one. However, i dont like to see the ".exe" extension in the start menu. And spaces in the name didnt work for me so I improved the script for me by adding a dialog where you can change the displayed name

@set usrchoice={Rs|Enter name for start menu entry:|{os!}}
@set lnkname= {$usrchoice}.lnk
Copy MAKELINK TO /start\Programs AS={$lnkname}
1 Like

I switched to a solution with jscript for removing the ".exe" extension by default and now definitly supporting spaces in the name.

@script Jscript
function OnClick(clickData)
{
	var lister = DOpus.listers.lastactive;
	var activetab = lister.activetab;
	var dlg = DOpus.Dlg;
	var defaultLinkName = activetab.selected_files(0).name_stem;
	var input = dlg.GetString("Enter name for start menu entry", defaultLinkName, 256, "OK|Cancel", "Enter the name for the link in start menu", DOpus.Listers(0)) + ".lnk";
	DOpus.NewCommand.RunCommand("Copy MAKELINK TO /start\\Programs AS=\"" + input + "\"");
}
1 Like

This is great, but it seems there is an issue with the script: if you press cancel when asked for a name, it will still add an item on the Start Menu with a name "undefined".

Thanks, didnt check for that case. The following code should fix this

@script Jscript
function OnClick(clickData)
{
	var activetab = clickData.sourcetab;
	var selectedFile = activetab.selected_files(0);
	var defaultLinkName = selectedFile.name_stem;
	var dialog = clickData.func.Dlg();
	var input = dialog.GetString("Enter name for start menu entry", defaultLinkName, 256, "OK|Cancel", "Enter the name for the link in start menu", DOpus.Listers(0)) + ".lnk";
	if(dialog.result == 1)
		DOpus.NewCommand.RunCommand("Copy MAKELINK TO /start\\Programs AS=\"" + input + "\"");
}

1 Like

Slight improvement: If you use clickData.func.Dlg() to make dialog object, it'll come set up with the lister as the parent window, which makes it work a bit better.

(You can also use DOpus.Dlg and then set the parent window of it to clickData.func.sourcetab for the same result but an extra line of code. On the other hand, you might run into problems using DOpus.Lister(0) as the parent window because it could be an unrelated lister.)

2 Likes

Thanks for the advise Leo :slight_smile: I've updated my last post with this change.
Is it then useful to replace
var activetab = DOpus.listers.lastactive.activetab;
with
var activetab = clickData.sourcetab; ?
Or doesnt this matter at all?

2 Likes

Yes, that's also a good change. I missed that. It will ensure the command uses the tab it was launched from. That's usually the active tab but there can be situations where it's not.

1 Like

Hi
I used the javascript version for another conext menu based script.
But it failed with TypeError: 'undefined' is Null or not an Object (without any hint where it came from, but since I was coding this functionality it was clear to me).
I was able to track it down to var activetab = clickData.sourcetab; which i tested for activetab == null and it was null, but clickdata did not seem to be null.
var activetab = DOpus.listers.lastactive.activetab;
instead worked for me.
Any idea about this?

What/where are you right-clicking when that happens?

I wanted a menu for creating a link to exe files in the startup folder. So via file types => system filetypes => *.exe => context menu

@script JScript
function OnClick(clickData)
{
	var tab = DOpus.listers.lastactive.activetab;
	var selectedFile = tab.selected_files(0);
	var linkName = selectedFile.name_stem;
	var cmd = clickData.func.command;
	cmd.AddFile(selectedFile);
	cmd.RunCommand("Copy MAKELINK TO /start\\Programs\\Startup AS=\"" + linkName + ".lnk\"");
}

this code with the initialization for tab works

So you're right-clicking a .exe file?

In the main file display, or in another part of the UI?

Is it a normal folder or something more exotic?

You shouldn't need scripting for that, FWIW. This should do it by itself as a single-line command:

Copy MAKELINK TO /start\Programs\Startup AS "{file|noext}.lnk"

(As long as only one thing is selected at a time, but that's also true of the script code as it currently is.)

Yes

In the main file display in a tab via context menu

Normal folder on another partition than c: (p: in my case)

Thanks didnt really think about that way but then, as you say, it wont work if more than one file is selected (tbh that shouldnt happen for that command in general).
Thanks!