“不允许用户交互"在 python 中运行 AppleScript 时 [英] "No user interaction allowed" When running AppleScript in python

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

问题描述

我有applescript,它将显示菜单列表并允许用户选择菜单项等.它本身运行良好.现在我尝试在 python 中运行它.我得到不允许用户交互.(-1713) 错误.

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. 在同一个applescript中添加run函数,所以我所做的只是将main添加到run中

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

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

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

我试图在python中运行上面的导入操作系统定义主():os.system ('osascript -e "tell application "ApplesScript Runner" do script/Users/eee/applescript/iTune.scpt end tell"')

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 == 'ma​​in':主要的()两种方法都不行.谁能告诉我如何正确地做到这一点?

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

推荐答案

这是一个常见的错误.当您在 shell 中使用 OSAScript 运行脚本时,您必须告诉应用程序显示任何显示对话框"或选择列表对话框"或任何需要用户交互的内容.OSAScript 无法显示它们,所以告诉 Finder 之类的应用程序显示它们.使用这样的代码...

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."'

但这会起作用,因为我们告诉 Finder 这样做...

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'

所以最重要的是,您在 iTune.scpt 中的某处显示了一个对话框.在该脚本中,只需告诉 iTunes 或 Finder 显示它们即可.

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.

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

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