1

我在我的 OSX 10.7 (Lion) macbook pro 上运行了一个小 shell 脚本,用于osascript收集用户的输入。该脚本有时可以完美运行,有时会返回execution error: System Events got an error: No user interaction allowed. (-1713).

重新启动我的mac后它是否工作是稳定的 - 如果它工作,它将工作直到我重新启动;如果它不起作用,则在我重新启动之前它不会起作用;当我重新启动时,我无法预测它是否会工作,直到我尝试它,即使运行这是我重新启动后做的第一件事。

可以在 Terminal.app 中模拟脚本的相关部分(复制所有这些并将其粘贴到 Terminal.app):

echo $(/usr/bin/osascript <<-'__HEREDOC__'
tell application "System Events"
  activate
  set input to display dialog "What you type here should be returned:" default answer "" buttons {"Cancel", "OK"} default button 2
  return text returned of input as string
end tell
__HEREDOC__
)

如果该代码向您显示一个对话框,它对您有用。如果它显示“无用户交互...”错误,则它不适合您。如果您重新启动,它可能会从工作切换到不工作或返回。

谷歌返回几千个结果'osascript“不允许用户交互”',但我找不到其他人遭受我得到的不一致结果。有些人建议一种解决方法,包括保存脚本文件并从 AppleScript 执行它

on run {sourcefile}
tell application “AppleScript Runner”
  do script sourcefile
end tell
end run

......我没有尝试过,因为它看起来非常难看。什么可能导致这有时不起作用?您将如何解决此类问题?

4

0 回答 0