Syed Umar AnisCommand Linennn file manager: Developed plugins for integrating with MacOS clipboard
Syed Umar AnisCommand Linennn file manager: Developed plugins for integrating with MacOS clipboard
Command Line

nnn file manager: Developed plugins for integrating with MacOS clipboard

On the Linux platform, the drag-and-drop plugin enables nnn to work with other GUI applications like Email, Slack, Finder etc. but no such option is available for MacOS. This limits the usability of nnn on MacOS.

I have implemented two plugins to support file copy and paste from a MacOS clipboard. This will help share files between nnn and other GUI programs.

These plugins are merged into the core nnn repository. You can find them here: cbcopy-mac and cbpaste-mac.

Copy file to MacOS clipboard

#!/usr/bin/osascript

# Description: Copy the hovered file to MacOS clipboard.
#
# Note: Supports only MacOS
#
# Shell: POSIX compliant
# Author: Syed Umar Anis


on run args
  set filePath to (second item of args & "/" & first item of args)
  tell application "Finder" 
    set the clipboard to (filePath as POSIX file)
  end tell
end

Paste files from MacOS clipboard

#!/usr/bin/env sh
# shellcheck disable=all

# Description: Paste the clipboard files into the current directory.
#              Only works if clipboard contents are files.
#
# Note: Supports only MacOS
#
# Shell: POSIX compliant
# Author: Syed Umar Anis


fs=($( osascript -e "use framework \"Foundation\"
    property this : a reference to the current application
    property NSPasteboard : a reference to NSPasteboard of this
    property NSURL : a reference to NSURL of this
    property pb : a reference to NSPasteboard's generalPasteboard

    property text item delimiters : linefeed

    pb's readObjectsForClasses:[NSURL] options:[]
    (result's valueForKey:\"path\") as list as text" ))

cp -R "${fs[@]}" "$2/"
Hi, I’m Umar

Leave a Reply

Your email address will not be published. Required fields are marked *