问题标签 [nspasteboard]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
527 浏览

python - Python脚本中NSPasteboard输出中的额外字符

我的第一篇文章……</p>

我正在使用 python 脚本从 Mac OS X Lion 上的剪贴板上获取文本。

我使用以下功能设置剪贴板:

where text= "一些文字"

我使用以下内容检索剪贴板:

输出前面带有“u”,文本用引号括起来,如下所示:

如何检索应该输入到剪贴板的文本?

我对 NSPasteboard 一无所知。我在 stackoverflow 上找到了这些代码片段。

提前致谢。

附录:我的实际代码

这就是我在 ipython 中运行它时发生的情况:

输出前面带有“u”,文本用引号括起来,如下所示:

尝试了答案中的建议***

不去。:-(

是的。我只需要这样做:

我现在有

0 投票
1 回答
764 浏览

objective-c - 如何允许我的 NSTableView 委托/数据源句柄复制/粘贴/等

我有一个NSTableView我希望能够突出显示 1 行或更多行的地方,然后点击delete键删除它们,或者点击⌘</kbd>+C to copy them to the pasteboard.

我找到了一个将 NSTableView 子类化的建议,然后编写一个方法

-(void)copy:(id)sender

文档说NSTableView很少需要子类化。相反,使用 dataSource 或委托,或子类化子组件。委托和数据源协议不处理菜单命令或键盘快捷键。如果我尝试子类化,我会遇到一个问题,即子类需要向委托发送消息,但我的自定义方法不是协议的一部分,因此编译器会抱怨。与其对抗设计模式,我更愿意知道解决这个问题的“正确”方法是什么。

0 投票
0 回答
1070 浏览

objective-c - 将 NSPasteboardItem 与粘贴板分离

我想在高层次上做的是使用此代码存储粘贴板上的当前数据(任何类型的数据),我认为这是正确的:

然后我存储pasteboardItems以备后用。我的问题是,当我尝试将相同的数据写入粘贴板时:

我正在做的是用NSPasteboardItem我之前制作的数组传入一个数组。然后我得到这个错误:

我有点困惑,因为NSPasteboardItem我试图写入粘贴板的内容与任何粘贴板都没有关联,因为我自己实例化了它并且从未从粘贴板中检索过它。感谢您的帮助,如果您需要更多详细信息,请告诉我。

0 投票
1 回答
2091 浏览

macos - 从 OS X 中的剪贴板获取文件路径

我希望我的应用程序之前将文件的完整路径复制到剪贴板。

我试过这个:

这仅返回文件名,而不是路径。

你能帮助我吗?

0 投票
1 回答
770 浏览

cocoa - 在核心数据中复制/粘贴自定义托管对象

我很难复制/粘贴来处理我的自定义托管对象Person。该对象包含属性和关系。对象应提供 objectID。我打算实现粘贴生成一个新对象,然后从复制的Person.

复制 objectID 可能确实有效。我确信粘贴不起作用。我在我的Person类中实现了以下方法,以尝试复制/粘贴对象:

并进行粘贴:

我应该如何在这里进行?我不知所措,阅读了许多 stackoverflow 问答(例如 Peter Hosey 对NSPasteboard 和简单自定义数据的出色回答)以及 Apple 文档,但我仍然对此感到困惑。

0 投票
2 回答
599 浏览

cocoa - 确定当前粘贴板内容的源应用

来自 AppStore 的几个 OSX 剪贴板管理器显示了确定复制到剪贴板的内容的源应用程序的能力。

我正在编写一些简单的剪贴板观察者,并希望在内容附近显示源应用程序图标,存储在一般的 NSPasteboard 中。我想知道如何实现这一点。

据我所知,除了数据类型和数据本身之外,NSPasteboard 不提供任何其他信息。

也许有一些事件或通知知道触发了“复制”命令?还是其他一些方法?

0 投票
2 回答
1837 浏览

objective-c - Reading Multiple Dragged-n-Dropped Files

I have a small window inside the main xib (MainMenu.xib) with an NSImageView control for an OS X application. This view control has an NSImageView subclass that is supposed to accept files that the user brings (drag n drop). Since I have no experience in developing a Mac application with Objective-C, I've searched around, checking out some sample projects from Apple, and got some idea. Well, to make the story short, I've just copied the code posted here. It works. Great... The following is a concise version.

For now, the drop box only gets file paths one at a time regardless of the number of files the user drags and drops onto the drop box. So what I would like to know is how to get the application to read all multiple files the user brings.

Thank you,

0 投票
1 回答
2622 浏览

macos - Mac 监听事件:复制到粘贴板

我正在阅读 NSPasteboard,然后想找到....

  1. 我正在尝试找到正确的通知方法来侦听数据的复制事件到剪贴板。

  2. 此外,我正在尝试查找复制到剪贴板的数据的文件路径。这将是一个粘贴板对象。

  3. 如果我从浏览器中的页面复制文本,我试图找出如何获取复制文本的页面的 url 地址。

有任何想法吗?

0 投票
1 回答
386 浏览

objective-c - NSPasteboard:拖动不同类型的多个对象

我想将数据从我的应用程序复制到 Numbers 或 Excel 工作表中。数据主要由整数组成,但也有一些图像。我尝试通过首先将数据放入 NSTableView 中,然后通过以下方法将数据写入粘贴板来完成此操作:

如果我最后不添加 NSImage,所有数据都会被很好地复制,但是一旦我将 NSImage 添加到数组中,只有图像被复制,如果我添加两个 NSImage,只有第一个被复制。我错过了什么?

任何想法将不胜感激!

编辑:顺便说一句,我刚刚意识到,即使是 Numbers.app 也无法将带有文本和图像的复制单元格拖动到 Excel 和 TextEdit 中。但是,在 Numbers 文件之间有效。

0 投票
1 回答
216 浏览

xcode - Why is Xcode's Search Navigator pulling searches from Safari?

I often have Safari open while working on a project in Xcode, looking up stuff on Stack Overflow and the like. A few times, I've searched something in to the web address/search engine field of Safari, and a word or two from what I typed in and it will be entered into the Search Navigator in Xcode, even though I didn't type it in there. It doesn't do it every time.

EDIT: Text entered in through the Search Navigator can pop up in Safari too.

This doesn't cause any problems, but the words it picks don't seem to have any relevance, and I'm curious as to why this oddity is happening.

I'm running Xcode 4.6.3, Safari 6.0.3, and Mac OS X 10.8.4

Is this a glitch? A half-baked feature?