Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/mercurial/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Macos Applescript只工作一次_Macos_Applescript_Osx Yosemite - Fatal编程技术网

Macos Applescript只工作一次

Macos Applescript只工作一次,macos,applescript,osx-yosemite,Macos,Applescript,Osx Yosemite,我还在学习AppleScript的基础知识。 当我尝试运行一个简单的“Hello World”脚本时,如: tell application "TextEdit" activate end tell tell application "System Events" keystroke "Hello World!" key code 36 end tell 我第一次运行它时,它在文本编辑中写下了“Hello World!”,这是它应该做的。 但第二次,它在脚本编辑器中写“

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

tell application "TextEdit"
    activate
end tell
tell application "System Events"
    keystroke "Hello World!"
    key code 36
end tell
我第一次运行它时,它在文本编辑中写下了“Hello World!”,这是它应该做的。 但第二次,它在脚本编辑器中写“Hello World!”。 从那时起,它将只在脚本编辑器中编写

我是不是在剧本中遗漏了一些明显的东西? 或者我应该看看OSX的哪些方面


提前谢谢!请随意回答冗长的答案、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

你可以改进你的答案,解释它是如何解决OP问题的
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