Macos Applescript只工作一次
我还在学习AppleScript的基础知识。 当我尝试运行一个简单的“Hello World”脚本时,如: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!”,这是它应该做的。 但第二次,它在脚本编辑器中写“
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