【发布时间】:2019-02-01 06:54:38
【问题描述】:
我有一个关于在 MacOS 应用程序中运行 applescript 的问题。
我想创建一个 Mac 应用程序,它可以执行 Applescript 以在 Chrome 上复制选定的文本。
这里是 Applescript:
tell application "Google Chrome"
activate
try
tell application "System Events"
keystroke "c" using {command down}
end tell
on error
display dialog "error" buttons {"OK"}
end try
end tell
delay 1
set selectedText to the clipboard
我的想法是我将这个 Applescript 保存在分布式 Mac App 中,让应用程序执行这个脚本。
在开发环境中(编译成{Appname}.app之前),可以成功切换到Chrome并复制选中的文本。
但是,将其捆绑为{Appname}.app后,如果Chrome尚未运行,则可以激活Chrome,但无法执行Command + C键盘组合。
我的猜测是应用程序没有询问Accessibility in Security Setting,所以我添加它并打开它。但是还是不行。
我也尝试添加entitlement 设置,但仍然失败:
<key>com.apple.security.temporary-exception.apple-events</key>
<array>
<string>com.google.Chrome</string>
<string>com.apple.systemevents</string>
</array>
有人知道可能的解决方案吗?
我是 Mac App 开发的新手。任何提示都非常受欢迎。谢谢!
【问题讨论】:
标签: macos applescript