Atom, Xlwings permission error in MacBook M1, "Command Error -1743: The User has declined permission"

Viewed 263

I recently moved from Windows to the New MacBook Pro M1.

Current version of my software and OS:

  • macOS Monterey 12.2.1
  • Anaconda and Jupiter Notebook (all latest version)
  • Atom:1.59.0
  • Python: 3.9
  • Xlwings 2.4

My issue (see attached pic), when execute a very simple test code for xlwings, the xlwings package is successfully imported, but when I am try to create excel App() instance, the MacOS or Atom (I am not sure which one) is throwing out Command Error

import xlwings as xw
xw.App()

Command Error

---------------------------------------------------------------------------
EventError                                Traceback (most recent call last)
~/opt/anaconda3/lib/python3.9/site-packages/aeosa/appscript/reference.py in __call__(self, *args, **kargs)
    481                 try:
--> 482                         return self.AS_appdata.target().event(self._code, params, atts, codecs=self.AS_appdata).send(timeout, sendflags)
    483                 except aem.EventError as e:

~/opt/anaconda3/lib/python3.9/site-packages/aeosa/aem/aemsend.py in send(self, timeout, flags)
     91                                                         errormsg = _defaultcodecs.unpack(errormsg)
---> 92                                                 raise EventError(errornum, errormsg, eventresult)
     93                                 if kae.keyAEResult in eventresult: # application has returned a value

EventError: Command failed: The user has declined permission. (-1743)

The above exception was the direct cause of the following exception:

CommandError                              Traceback (most recent call last)
/var/folders/wl/2tgm3h1j69l7w_63j50vg8_r0000gn/T/ipykernel_3668/1252992621.py in <module>
----> 1 xw.App()

~/opt/anaconda3/lib/python3.9/site-packages/xlwings/main.py in __init__(self, visible, spec, add_book, impl)
    215             self.impl = xlplatform.App(spec=spec, add_book=add_book, visible=visible)
    216             if visible or visible is None:
--> 217                 self.visible = True
    218         else:
    219             self.impl = impl

~/opt/anaconda3/lib/python3.9/site-packages/xlwings/main.py in visible(self, value)
    284     @visible.setter
    285     def visible(self, value):
--> 286         self.impl.visible = value
    287 
    288     def quit(self):

~/opt/anaconda3/lib/python3.9/site-packages/xlwings/_xlmac.py in visible(self, visible)
    112     @visible.setter
    113     def visible(self, visible):
--> 114         appscript.app('System Events').processes[its.unix_id == self.pid].visible.set(visible)
    115 
    116     def quit(self):

~/opt/anaconda3/lib/python3.9/site-packages/aeosa/appscript/reference.py in __call__(self, *args, **kargs)
    516                                                 return
    517                                         raise CommandError(self, (args, kargs), e, self.AS_appdata) from e
--> 518                         raise CommandError(self, (args, kargs), e, self.AS_appdata) from e
    519 
    520         def AS_formatcommand(self, args):

CommandError: Command failed:
        OSERROR: -1743
        MESSAGE: The user has declined permission.
        COMMAND: app('/System/Library/CoreServices/System Events.app').processes[its.unix_id == 3731].visible.set(True)
Press any key

Test I carried out:

  • the script was successfully executed with Terminal (with the same anaconda env)
  • the code was successfully executed with Jupiter Notebook (with the same anaconda env)
  • I tried the code on my other Windows laptop with atom, it works with no problem
  • I launch Atom by using terminal and execute the code again, it still showing the same permission error

Could anyone help with the matter please? Much appreciate in advance.

0 Answers
Related