GP SoftwareTwitter
Opus FAQsManualCommandsObjects

How to open a shortcut(.lnk) from a command

I want to open a shortcut file (.lnk) from a command.

I'm very new to this and so please bear with me. I can use the GO command to open a specific folder. For example:
GO path "C:"

However, specifying a shortcut file (.lnk) does nothing. For example,
GO path "C:\System32.lnk"

As I write, I'm thinking maybe this is because it is a file and not a folder.

My question remains, how do I get Opus to display a shortcut to a folder?

Thanks,

This works for me:

GO "C:\Windows\System32.lnk"

Just make sure you have the full path to the link in the quotes (and the right path, of course).

Another option might be to create an alias if you want a shorter command. If so, take a look at the help on aliases.

Quotes are are good habit, but only technically needed if the path contains spaces.

I think that command would take you to C:\Windows and select System32.lnk (if it exists), though? At least that's what it does from a quick test. I don't think it looks at what the shortcut points to at all.

GO C:\System32.lnk OPENCONTAINER=target gets us slightly closer, but still not all the way. It will go to the parent or what the shortcut points to and select the file or folder that the shortcut points to. But we want to go into that folder, not have it selected.

What we really want to do is the same thing that would happen if the shortcut was double-clicked. In fact, the answer is deceptively simple; just run the shortcut itself:

C:\System32.lnk

That's all you need.

This is good advice. Aliases may be an easier tool here, unless you have things external to Opus which depend on the shortcuts and you want to ensure everything is defined in one place.

As an example, Go /system32 will take you to the system32 folder, working out the correct location on any given machine. There are lots of built-in aliases and you can also add your own. You can find them all under Preferences / Favorites and Recent / Folder Aliases.

Chuck and Leo, Thank you very much for your responses.

As I said, I'm a newbie at writing Opus commands and your answers have given me more insight. They have also given me better understanding of the language used to describe commands.

I'm not there yet.

GO "C:\Windows\System32.lnk" opens the parent folder of file "System32.lnk", viz "C:"
GO C:\System32.lnk OPENCONTAINER=target` opens the parent folder of link's target, viz "C:\Windows"
The suggested solution, deceptively simple C:\System32.lnk
unfortunately throws up an error.

I also tried GO "C:\System32.lnk" but it gave the same error.

I'm using the Opus CLI Editor Tool to test the commands. The error message is 'Unknown Command'.

My goal is to use a command to open a link in the same way as double-clicking on the link does.

I'm not quite sure what to try next. I'm using Opus 12.19. Win7 x32. Opus is set to Replace Explorer for All Folders.

Double clicking on the lnk file, C:\System32.lnk works correctly.

Thanks for the suggestion of using aliases to go straight to the System32 folder. I'm afraid in my attempt to simplify the description of the problem I've given you the wrong idea about my need. Once I have a command to 'launch' the folder shortcut, I'm going to modify the path to use a different drive letter but first I must be able to launch the shortcut. This is the first stage of my context menu that makes a link use a local version of the target, not the hard-coded one. I've got some ideas on how I will change the path.

You don't want the GO command at all. Just run C:\System32.lnk by itself, without any other commands or arguments.

That tool can only run internal commands. Put the command in a button or hotkey and it will work. Or run it via the command field you get if you type > into a file display.

You can change aliases after creating them as well. It makes sense to use shortcuts if you need to access them from outside of Opus, but if everything you're doing is inside of Opus then aliases are probably better.

Thanks, Leo. I thought the Opus CLI would allow me to test code without going into and out of FileTypes. It has taught me that Opus CLI is not quite what I thought. All good learning.

I've solved my problem. When I wrote to the forum for help with my initial problem I was writing code for a 'folder' context menu. My shortcuts point to folders but the shortcut itself is a FILE!!! Glad I got that cleared up.

I've now progressed and have the code I was aiming for: a context menu command that will change the drive letter of a shortcut target for the purpose of opening a similar folder.

My code is:

@set DL={filepath|}
go {filepath} opencontainer=target
"{$DL}{filepath|noroot}"

It works a treat. Thanks for your help.

{filepath} on its own should work, replacing all three lines, if the aim is to do the same thing as double-clicking the selected shortcut.

Hi Leo.

The goal is to alter the target path of the shortcut. An example.

C:\C-Drive\Users.lnk is a shortcut to folder C:\Users. If this shortcut is on another drive because C: has been backed up to say the R: drive, then the shortcut R:\C-Drive\Users.lnk still has C:\Users as a target. That's fine under normal circumstances but sometimes I want the link to be a shortcut to R:\Users. This is helpful if I want to check or retrieve some user settings from a recent backup.

My code reads the drive letter of the current shortcut and uses it as a replacement for the drive letter in the target path.

I only invoke this through a context menu command.

Leo, Is there a filename code for the shortcut target? That would enable me to simplify my three line code.

No filename code, but scripts can look up shortcut targets, fwiw.

Thanks, Leo. I don't need my context menu very often and so what I've got is good enough.

Thanks for your help.

1 Like