注意是复制文件到剪贴板,不是文件内容,目前找到好多命令都是复制内容的,比如 pbcopy 命令范围 shell osascript python 都行,或者有更好的替代方法
我描述一下mac 下复制一个文件,我用 alfred 剪贴板访问的时候是这样的
而 pbcopy 得到的是a.txt 的内容并不是文件
我需要图中这种形式,就是命令复制后,到一个文件夹直接能粘贴这个文件,而不是仅仅复制了文件的内容
1
lxk11153 Aug 23, 2020
蹲一个~
|
2
Kobayashi Aug 23, 2020 via Android
Finder 不知道有没有插件。我用 Forklift,自带此功能,也可以 Forklift 通过自定义命令实现。终端用 ranger 实现。
|
3
ihwbunny Aug 23, 2020
pbcopy | pbpaste
|
4
ihwbunny Aug 23, 2020
什么叫复制文件,而不复制内容?是文件全路径?
|
5
xgQikk Aug 23, 2020 via iPhone
你在说什么东西……
|
6
minamike Aug 23, 2020
tell application "Finder" to set theItems to selection
repeat with itemRef in theItems set the clipboard to (POSIX file (POSIX path of (itemRef as string))) end repeat |
7
Tink PRO 文件路径?
|
8
goldenlove Aug 23, 2020
直接 cp 或 scp 不香么?一定要走剪贴板?主要做啥用?
|
9
tyhunter Aug 23, 2020
临时收集文件吗?考虑下 Yoink 这类
|
10
lxk11153 Aug 23, 2020
@goldenlove #8 可能是类似在 Finder 里先 cmd+c,然后再另一个程序里 cmd+v 吧。
|
11
xgQikk Aug 23, 2020 via iPhone 我还是没听懂他在说什么 解释了这么多 还是没讲清
|
12
littlewing Aug 23, 2020
打开 iTerm2,执行 cp
|
13
lxk11153 Aug 23, 2020
|
14
Mysqto Aug 23, 2020 |
15
xurunfei OP @Mysqto 谢谢,就是要的这个 ,也谢谢大家的回复 ,需要的脚本如下
``` #!/usr/bin/osascript on run args set the clipboard to POSIX file (first item of args) end ``` |
16
ladychili Aug 25, 2020
hhhhhh
和 lz 的需求刚好逆向,想知道如何通过一个脚本 /命令获取剪贴板的图片(想做个 Alfred workflow 快速对剪贴板里的图片 google 以图搜图 |
17
xurunfei OP @ladychili 我这边整理了一点你看看有用没
``` # 复制文件 osascript -e 'set the clipboard to POSIX file ("/Users/xurunfei/Documents/tmp/a.png")' #从剪贴板获取数据然后当做文件路径复制回剪贴板, 这里只是文本,没有试过图片 osascript -e 'set theData to (the clipboard as text)' #另外 python 可以用下面这个从剪贴板读取图片 img = ImageGrab.grabclipboard() ``` |
18
dovme Aug 25, 2020
你可能需要的是这个软件 paste
https://i.loli.net/2020/08/25/mejKfRwQrY3WL6c.png |
20
ivyliner Sep 15, 2020 @xurunfei 我写了一个命令行工具, 解决 #15 楼的 Applescript 的缺点
1. 不支持批量 2. 不支持文件相对路径 项目地址: https://github.com/yujinqiu/pbadd |
21
xurunfei OP @ivyliner 好的谢谢,我主要是用在其他软件界面配合 touchbar 和 BetterTouchTool.app 的 applescript 使用,这样我能直接点击 touchbar 按钮直接复制软件对应的文件
|
22
yimq Mar 10, 2021
在 big sur 15 楼的脚本好像有权限问题,可以试试这个
qq() { file_real_path=$(realpath $1) osascript -e 'tell app "Finder" to set the clipboard to ( POSIX file '\"$file_real_path\"' )' open -a WeChat } |
24
Mysqto May 24, 2021
@Neoth https://gist.github.com/mysqto/e3826dbe2772acf1af8e74b0558157c0
``` #!/usr/bin/osascript use framework "Appkit" property this : a reference to current application property NSFileManager : a reference to NSFileManager of this property NSImage : a reference to NSImage of this property NSMutableArray : a reference to NSMutableArray of this property NSPasteboard : a reference to NSPasteboard of this property NSString : a reference to NSString of this property NSURL : a reference to NSURL of this property pb : missing value on run argv init() clearClipboard() addToClipboard(argv) end run to init() set pb to NSPasteboard's generalPasteboard() end init to clearClipboard() if pb = missing value then init() pb's clearContents() end clearClipboard to addToClipboard(fs) local fs set fURLs to NSMutableArray's array() set FileManager to NSFileManager's defaultManager() repeat with f in fs if f's class = alias then set f to f's POSIX path set pwd to (FileManager's currentDirectoryPath) set fn to (NSString's stringWithString:f) set fp to (pwd's stringByAppendingPathComponent:fn)'s stringByStandardizingPath() if (FileManager's fileExistsAtPath:fp) then (fURLs's addObject:(NSURL's fileURLWithPath:fp)) end if end repeat if pb = missing value then init() pb's writeObjects:fURLs end addToClipboard ``` |
25
DifferentDrum Feb 14, 2022
|
27
mayooot Dec 25, 2024
|