Creating shell links (.lnk) to files/folders

You want to talk about Far Manager, but don't know where to turn?
Post Reply
KlepetoX
Posts: 102
Joined: Sun 08 Jan, 2012 08:23
Location: Czech Republic

Creating shell links (.lnk) to files/folders

Post by KlepetoX » Mon 24 Mar, 2014 13:21

Is there any possibility to create shell link files in FAR as with http://plugring.farmanager.com/plugin.php?pid=43&l=en plugin? I mean some newer FAR3 plugin or maybe macro?

User avatar
NightRoman
Posts: 5872
Joined: Fri 18 Aug, 2006 13:52
Location: Cambridge, UK
Has thanked: 8 times
Been thanked: 9 times
Contact:

Re: Creating shell links (.lnk) to files/folders

Post by NightRoman » Mon 24 Mar, 2014 13:49

If you are familiar with PowerShell then this script may help:

New-Shortcut.ps1
  1. param(
  2.     [Parameter(Mandatory = $true)]
  3.     [string]$Target,
  4.     [string]$Shortcut
  5. )
  6.  
  7. $Target = $PSCmdlet.GetUnresolvedProviderPathFromPSPath($Target)
  8.  
  9. if (!$Shortcut) { $Shortcut = $Target + '.lnk' }
  10. [System.IO.File]::Delete($Shortcut)
  11.  
  12. $WshShell = New-Object -ComObject WScript.Shell
  13. $link = $WshShell.CreateShortcut($Shortcut)
  14. $link.TargetPath = $Target
  15. $link.Save()
The second parameter is optional (<target>.lnk is assumed)

User avatar
NightRoman
Posts: 5872
Joined: Fri 18 Aug, 2006 13:52
Location: Cambridge, UK
Has thanked: 8 times
Been thanked: 9 times
Contact:

Re: Creating shell links (.lnk) to files/folders

Post by NightRoman » Mon 24 Mar, 2014 13:56

So it is not a Far plugin. But you may connect it to Far via the user menu ([F2]), e.g. create a user menu command:

Code: Select all

PowerShell.exe -File ...\New-Shortcut.ps1 "!\!.!"
It creates lnk for the current panel item.

User avatar
John Doe
Бюрократ
Posts: 11395
Joined: Wed 27 Apr, 2005 20:42
Has thanked: 17 times
Been thanked: 101 times

Re: Creating shell links (.lnk) to files/folders

Post by John Doe » Mon 24 Mar, 2014 16:13

EMenu plugin (included in std distribution): F11/EMenu/Context Menu/...
or via command line: rclk_cmd:link <filename>

User avatar
NightRoman
Posts: 5872
Joined: Fri 18 Aug, 2006 13:52
Location: Cambridge, UK
Has thanked: 8 times
Been thanked: 9 times
Contact:

Re: Creating shell links (.lnk) to files/folders

Post by NightRoman » Tue 25 Mar, 2014 07:16

Forgot to add. FarNet module PowerShellFar provides the script Invoke-Shortcut-.ps1

Description:

The script gets a target path from the shortcut file (.lnk). If it is a
directory path this directory is opened on the current panel. If it is a
file path the action depends on parameters; default action is to jump to
the target file, other actions: edit or view the file.

Switch -Panel opens a shortcut in a panel to view and edit its properties.
If you change data it asks you to save changes on exit or you can use
[CtrlS] to save data at any moment.

How to open .lnk files, e.g. by [Enter], [CtrlPgDn], [F3], [F4]:
Open menu Commands \ File Associations, add an association and set:
-- Mask: *.lnk
-- Command for [Enter]: ps: Invoke-Shortcut- #
-- Command for [CtrlPgDn]: ps: Invoke-Shortcut- -Panel #
-- Command for [F3]: ps: Invoke-Shortcut- -View #
-- Command for [F4]: ps: Invoke-Shortcut- -Edit #

[Shift-Enter] still opens shortcut files from Far in standard Windows way.

Post Reply

Return to “General Discussions”