如何使用AppleScript控制字符串的粘贴?

如何使用AppleScript控制字符串的粘贴?,applescript,document,paste,bbedit,Applescript,Document,Paste,Bbedit,在BBEdit和AppleScript中,我可以循环浏览字符串,并使用以下命令将字符串设置到剪贴板: set the clipboard to jsonString 然后,我可以创建一个新的文本文档,并使用以下方法保存它: set jsonParseFile to (name of project window 1) as text save text document jsonParseFile to file ("some:location") without saving as stat

在BBEdit和AppleScript中,我可以循环浏览字符串,并使用以下命令将字符串设置到剪贴板:

set the clipboard to jsonString
然后,我可以创建一个新的文本文档,并使用以下方法保存它:

set jsonParseFile to (name of project window 1) as text
save text document jsonParseFile to file ("some:location") without saving as stationery
set jsonParseFile to (name of active document of project window 1) as string
但是当我尝试用
paste
粘贴字符串内容时,我得到一个错误,表明
paste
无法理解:

BBEdit出错:活动文档不理解“粘贴” 信息

因此,当我删除:

set jsonParseFile to (name of active document of project window 1) as string
和使用:

paste of active document
我得到了相同的错误,但当我仅使用
粘贴时,返回了以下错误:

BBEdit got an error: Can't continue paste.
如何将字符串粘贴到文件变量
jsonParseFile
中,该变量是最前面的文件,而无需调用:

tell active document of project window 1 to paste
而是用这样的东西:

tell active document of file jsonParseFile to paste
通过
jsonParseFile
?当我搜索时,除了按键之外,我没有发现任何东西,我不想使用,当我查字典寻找答案时,我没有得到多少:


这是一个如何将字符串粘贴到活动文档中的简单示例

set the clipboard to "Hello World"

tell application "BBEdit"
    tell active document of project window 1
        paste
    end tell
end tell

这是一个如何将字符串粘贴到活动文档中的简单示例

set the clipboard to "Hello World"

tell application "BBEdit"
    tell active document of project window 1
        paste
    end tell
end tell

我明白了,但我试图告诉变量
jsonString
,而不仅仅是项目窗口。任何东西都可能被意外设置为活动项目窗口。@Gʀᴍ, 您所说的“任何东西都可能意外地被设置为活动的项目窗口”。虽然这可能是真的,但程序员有责任确保在采取任何行动之前,正确的目标具有焦点。@user3439894但这不是问题的目的。我想在我的目标中细化,以确保出现任何可能的问题,而答案并不反映这一点。如果有多个窗口打开,那么这可能是一个问题。我明白了,但我试图告诉变量
jsonString
,而不仅仅是项目窗口。任何东西都可能被意外设置为活动项目窗口。@Gʀᴍ, 您所说的“任何东西都可能意外地被设置为活动的项目窗口”。虽然这可能是真的,但程序员有责任确保在采取任何行动之前,正确的目标具有焦点。@user3439894但这不是问题的目的。我想在我的目标中细化,以确保出现任何可能的问题,而答案并不反映这一点。如果有多个窗口打开,那么这可能是一个问题。