Page 1 of 1

Creating shell links (.lnk) to files/folders

Posted: Mon 24 Mar, 2014 13:21
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?

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

Posted: Mon 24 Mar, 2014 13:49
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)

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

Posted: Mon 24 Mar, 2014 13:56
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.

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

Posted: Mon 24 Mar, 2014 16:13
by John Doe
EMenu plugin (included in std distribution): F11/EMenu/Context Menu/...
or via command line: rclk_cmd:link <filename>

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

Posted: Tue 25 Mar, 2014 07:16
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.