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: 129
Joined: Sun 08 Jan, 2012 08:23
Location: Czech Republic
Has thanked: 2 times
Been thanked: 1 time

Creating shell links (.lnk) to files/folders

Post by KlepetoX »

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: 6184
Joined: Fri 18 Aug, 2006 13:52
Location: Cambridge, UK
Has thanked: 32 times
Been thanked: 62 times
Contact:

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

Post by NightRoman »

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

New-Shortcut.ps1
  1. param(
  2.  
  3.     [Parameter(Mandatory = $true)]
  4.  
  5.     [string]$Target,
  6.  
  7.     [string]$Shortcut
  8.  
  9. )
  10.  
  11.  
  12.  
  13. $Target = $PSCmdlet.GetUnresolvedProviderPathFromPSPath($Target)
  14.  
  15.  
  16.  
  17. if (!$Shortcut) { $Shortcut = $Target + '.lnk' }
  18.  
  19. [System.IO.File]::Delete($Shortcut)
  20.  
  21.  
  22.  
  23. $WshShell = New-Object -ComObject WScript.Shell
  24.  
  25. $link = $WshShell.CreateShortcut($Shortcut)
  26.  
  27. $link.TargetPath = $Target
  28.  
  29. $link.Save()
The second parameter is optional (<target>.lnk is assumed)
User avatar
NightRoman
Posts: 6184
Joined: Fri 18 Aug, 2006 13:52
Location: Cambridge, UK
Has thanked: 32 times
Been thanked: 62 times
Contact:

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

Post by NightRoman »

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: 13807
Joined: Wed 27 Apr, 2005 20:42
Has thanked: 73 times
Been thanked: 426 times
Contact:

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

Post by John Doe »

EMenu plugin (included in std distribution): F11/EMenu/Context Menu/...
or via command line: rclk_cmd:link <filename>
User avatar
NightRoman
Posts: 6184
Joined: Fri 18 Aug, 2006 13:52
Location: Cambridge, UK
Has thanked: 32 times
Been thanked: 62 times
Contact:

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

Post by NightRoman »

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”