"User interaction not allowed" When running AppleScript in python

I have applescript that displays a list of menus and allows the user to select menu items, etc. It works great on its own. And now I'm trying to run it in python. I get permission from user No. (-1713).

I looked online. I tried the following:

  • add the run function to the same applescript, so what I did was just add main to run

    at startup say the application "AppleScript Runner" main () end say end

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

    if name == ' main : main () None of them work. Can someone tell me how to do it right?

+1
source share
1 answer

This is a common mistake. When you run a script using OSAScript from the shell, how you do it, you must tell the application to show any "display dialogs" or "select list dialogs" or anything that requires user interaction. OSAScript cannot show them, so tell the application, like Finder, to show them. Use this code ...

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

Or from the command line this will not work ...

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

But it will work, as we tell Finder to do this ...

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

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

+10
source

Source: https://habr.com/ru/post/922404/


All Articles