0

我正在寻找 AppleScriptObjC 的方法,并且发现 Shane Stanley 的Everyday AppleScriptObjC很有帮助。但我仍然很难知道从哪里开始NSPasteboard

这是我到目前为止所拥有的:

use AppleScript version "2.4"
use framework "Foundation"
use framework "AppKit"
use scripting additions

on readClipboard(theClipboard)
    set theClipboard to current application's NSPasteboard
    return theClipboard as text
end readClipboard

set theContents to missing value
its readClipboard(theContents)

当然,这是行不通的。但它似乎确实在做些什么。

它返回:

error "Can’t make «class ocid» id «data optr000000002852F974FF7F0000» into type text." number -1700 from «class ocid» id «data optr000000002852F974FF7F0000» to text

任何指针将不胜感激。

4

1 回答 1

0

NSPasteboard是一个能够容纳许多不同种类的不同物品的容器。有一些标准粘贴板定义为NSGeneralPboard,NSRulerPboardNSDragPboard. 对于复制和粘贴操作,使用通用粘贴板。
存储在一般粘贴板中的项目也可能不同。可以在粘贴板内存储public.rtfpublic.jpeg

把它们放在一起,我们得到了这个解决方案:

    set theClipboard to current application's NSPasteboard's generalPasteboard's stringForType:(current application's NSPasteboardTypeString)

玩得开心,迈克尔/汉堡

于 2015-03-25T10:02:27.907 回答