【问题标题】:How can control the paste of a string with AppleScript?如何使用 AppleScript 控制字符串的粘贴?
【发布时间】:2017-12-01 01:23:59
【问题描述】:

在 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

我得到了同样的错误,但是当我只使用 paste 时,我返回了以下错误:

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?当我搜索时,除了击键之外我没有找到任何东西,我不想使用,当我检查字典以获取答案时,我没有得到太多:

【问题讨论】:

    标签: applescript document paste bbedit


    【解决方案1】:

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

    set the clipboard to "Hello World"
    
    tell application "BBEdit"
        tell active document of project window 1
            paste
        end tell
    end tell
    

    【讨论】:

    • 我明白了,但我试图告诉变量jsonString 而不仅仅是项目窗口。任何东西都可能被意外设置为活动项目窗口。
    • @Gʀɪᴍ,您说“任何东西都可能被意外设置为活动项目窗口。”虽然这可能是正确的,但程序员有责任确保在采取任何行动之前有适当的目标可以采取行动。
    • @user3439894 但这不是问题的意图。我想在我的定位中细化,以确保出现任何可能的问题并且该答案并未反映这一点。如果打开了多个窗口,那么这可能是个问题。
    猜你喜欢
    • 2014-03-12
    • 1970-01-01
    • 1970-01-01
    • 2015-07-17
    • 1970-01-01
    • 2017-02-04
    • 1970-01-01
    • 1970-01-01
    • 2013-05-27
    相关资源
    最近更新 更多