"不允许用户交互"当蟒蛇运行的AppleScript [英] "No user interaction allowed" When running AppleScript in python

查看:306
本文介绍了"不允许用户交互"当蟒蛇运行的AppleScript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有AppleScript的这将显示菜单列表,并允许用户选择菜单项等。
它本身运行正常。现在,我尝试在Python运行它。我得到允许任何用户交互。 (-1713)错误。

我在网上看了。我试过如下:


  1. 在运行功能添加在相同的AppleScript,所以我所做的是只需添加到主运行

    在运行
     告诉应用程序AppleScript运行
      主要()
     告诉结束
    运行结束


  2. 我试图运行在python以上
    进口OS
    高清的main():
      使用os.system('osascript -e告诉应用程序ApplesScript飞人做剧本/Users/eee/applescript/iTune.scpt结束说')

    如果命名 =='主要
       主要()
    无论是工作方式。谁能告诉我如何正确地做到这一点?



解决方案

这是一个常见的​​错误。当使用从shell OSAScript,因为你正在做的运行一个脚本,那么你必须告诉应用程序显示的显示对话框或选择列表对话框需要用户交互或任何东西。 OSAScript不能显示他们,告诉应用程序与Finder一样向他们展示。使用code这样的...

 告诉应用程序发现者
    启用
    显示对话框现在它的作品!
告诉结束

或命令行通知,这是不行的......

  osascript -e'显示对话框现在是行不通的。'

但是,这将工作,因为我们告诉Finder来做到这一点...

  osascript -e'告诉应用程序发现者-e激活-e显示对话框现在它的作品!'-e'端告诉

所以,底线是,在某处你iTune.scpt你显示一个对话框。在该脚本只是告诉iTunes或Finder中显示出来。

I have the applescript which will displays menu list and allow user to select menu items etc. It runs fine by itself. And now I try to run it in python. I get the No user interaction allowed. (-1713) error.

I looked online. I tried the following:

  1. add on run function in the same applescript, so what i did is just add the main into the run

    on run tell application "AppleScript Runner" main() end tell end run

  2. i tried to run the above in python import os def main(): os.system ('osascript -e "tell application "ApplesScript Runner" do script /Users/eee/applescript/iTune.scpt end tell"')

    if name == 'main': main() Neither way works. Can anyone tell me how to do this correctly?

解决方案

That's a common mistake. When you run a script using OSAScript from a shell, as you are doing, then you must tell an application to show any "display dialogs" or "choose list dialogs" or anything that requires user interaction. OSAScript can't show them so tell an app like the Finder to show them. Use code like this...

tell application "Finder"
    activate
    display dialog "Now it works!"
end tell

Or from the command line notice this won't work...

osascript -e 'display dialog "Now it will not work."'

But this will work since we tell the Finder to do it...

osascript -e 'tell application "Finder"' -e 'activate' -e 'display dialog "Now it works!"' -e 'end tell'

So bottom line is that somewhere in your iTune.scpt you are displaying a dialog. In that script just tell iTunes or the Finder to display them.

这篇关于"不允许用户交互"当蟒蛇运行的AppleScript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆