注意是复制文件到剪贴板,不是文件内容,目前找到好多命令都是复制内容的,比如 pbcopy 命令范围 shell osascript python 都行,或者有更好的替代方法
注意是复制文件到剪贴板,不是文件内容,目前找到好多命令都是复制内容的,比如 pbcopy 命令范围 shell osascript python 都行,或者有更好的替代方法
我描述一下mac 下复制一个文件,我用 alfred 剪贴板访问的时候是这样的
而 pbcopy 得到的是a.txt 的内容并不是文件
我需要图中这种形式,就是命令复制后,到一个文件夹直接能粘贴这个文件,而不是仅仅复制了文件的内容
|
lxk11153Aug 23, 2020
1
蹲一个~
|
|
KobayashiAug 23, 2020 via Android
2
Finder 不知道有没有插件。我用 Forklift,自带此功能,也可以 Forklift 通过自定义命令实现。终端用 ranger 实现。
|
|
ihwbunnyAug 23, 2020
3
pbcopy | pbpaste
|
|
ihwbunnyAug 23, 2020
4
什么叫复制文件,而不复制内容?是文件全路径?
|
|
xgQikkAug 23, 2020 via iPhone
5
你在说什么东西……
|
|
minamikeAug 23, 2020
6
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 |
|
TinkAug 23, 2020 via Android
7
文件路径?
|
|
goldenloveAug 23, 2020
8
直接 cp 或 scp 不香么?一定要走剪贴板?主要做啥用?
|
|
tyhunterAug 23, 2020
9
临时收集文件吗?考虑下 Yoink 这类
|
|
lxk11153Aug 23, 2020
10
@goldenlove #8 可能是类似在 Finder 里先 cmd+c,然后再另一个程序里 cmd+v 吧。
|
|
11
我还是没听懂他在说什么 解释了这么多 还是没讲清
|
|
littlewingAug 23, 2020
12
打开 iTerm2,执行 cp
|
|
lxk11153Aug 23, 2020
13
|
|
14
|
|
15
@Mysqto 谢谢,就是要的这个 ,也谢谢大家的回复 ,需要的脚本如下
``` #!/usr/bin/osascript on run args set the clipboard to POSIX file (first item of args) end ``` |
|
ladychiliAug 25, 2020
16
hhhhhh
和 lz 的需求刚好逆向,想知道如何通过一个脚本 /命令获取剪贴板的图片(想做个 Alfred workflow 快速对剪贴板里的图片 google 以图搜图 |
|
17
@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() ``` |
|
dovmeAug 25, 2020
18
你可能需要的是这个软件 paste
https://i.loli.net/2020/08/25/mejKfRwQrY3WL6c.png |
|
20
@xurunfei 我写了一个命令行工具, 解决 #15 楼的 Applescript 的缺点
1. 不支持批量 2. 不支持文件相对路径 项目地址: https://github.com/yujinqiu/pbadd |
|
21
@ivyliner 好的谢谢,我主要是用在其他软件界面配合 touchbar 和 BetterTouchTool.app 的 applescript 使用,这样我能直接点击 touchbar 按钮直接复制软件对应的文件
|
|
yimqMar 10, 2021
22
在 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 } |
|
MysqtoMay 24, 2021
24
@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 ``` |
|
DifferentDrumFeb 14, 2022
25
|
|
mayoootDec 25, 2024
27
|