繁体   English   中英

Applescript只能使用一次

[英]Applescript only works once

我仍在学习AppleScript的基础知识。 当我尝试运行一个简单的“ Hello World”脚本时,例如:

tell application "TextEdit"
    activate
end tell
tell application "System Events"
    keystroke "Hello World!"
    key code 36
end tell

我第一次运行它时,它写的是“ Hello World!”。 应该在TextEdit中。 但是第二次,它写了“ Hello World!”。 在脚本编辑器中。 从那时起,它将仅在脚本编辑器中编写。

我在脚本中缺少明显的东西吗? 还是我应该关注OS X?

提前致谢! 随意回答冗长的答案,Kbase文章或我可能错过的其他讨论话题。

tell application "TextEdit" to activate
tell application "System Events"
    tell application process "TextEdit" to set frontmost to true
    keystroke "Hello World!" & return
end tell

试试这组代码。 我将在下面使用注释(-)解释其工作方式。

tell application "TextEdit"

    -- Activate TextEdit and bring it to the foreground
    activate

    -- Create a new document and assign it to a variable called 'myDocument'
    set myDocument to make new document

    -- Activate the above mentioned new document
    tell myDocument

        -- Add text to the above mentioned new document
        set its text to its text & "Hello, world!"

    end tell
end tell

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM