Python Script - Not authorized to send Apple events to Calen

Posted on
Sat Jan 14, 2023 3:02 pm
RickStreet offline
Posts: 29
Joined: Jun 30, 2008

Python Script - Not authorized to send Apple events to Calen

I have a Python sciprt that calls an AppleScript to check for Holidays or Vacation. When I run it as attached or external it gives my an error: Not authorized to send Apple events to Calendar. The AppleScript runs fine from the Apple Script Editor. Is this a permission issue when Indigo runs scripts? Is there a fix?

Python Script:

Code: Select all
import time
import applescript

path_to_script_file = "/Users/Rick/Scripts/Calender Today.scpt"
my_ascript_from_file = applescript.AppleScript(path=path_to_script_file)

indigo.server.log("Checking if hoiday...")
   
reply = my_ascript_from_file.run()

if reply:
   indigo.variable.updateValue("holiday", value="true")
   indigo.server.log("hoiday set to true")
else:
   indigo.variable.updateValue("holiday", value="false")
   indigo.server.log("hoiday set to false")


AppleScript:
Code: Select all
set theDestCalendar to "House"
-- set startDate to date ((date string of (current date)) & " 00:00:00 am")
set startDate to (current date) -- (24 * 60 * 60)
set hours of startDate to 0
set minutes of startDate to 0
set seconds of startDate to 0

-- set endDate to (startDate + 2 * (24 * 60 * 60))
set endDate to startDate + (1 * days) - 1

tell application "Calendar"
   
   set theEvents to events of calendar theDestCalendar whose start date is greater than or equal to startDate and start date is less than or equal to endDate
   
   repeat with theItem in theEvents
      set eventTitle to summary of theItem
      -- say eventTitle
      if eventTitle contains "Holiday" or eventTitle contains "Vacation" then
         return true
      end if
      
   end repeat
   
   return false
   
   -- set eventTitle to summary of (item 1 of theEvents)
   
end tell

Rick

Posted on
Mon Jan 16, 2023 6:20 pm
jay (support) offline
Site Admin
User avatar
Posts: 18224
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Python Script - Not authorized to send Apple events to C

That's macOS being ever so security conscious (to the point of being useless IMO)... :roll:

Try this:
  1. Open a terminal window
  2. Enter the following command (substitute the path to your python script):
    Code: Select all
    indigo-host -x /path/to/script.py

Hopefully, that will result in macOS prompting you to allow the script to run.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Thu Jan 19, 2023 3:51 pm
RickStreet offline
Posts: 29
Joined: Jun 30, 2008

Re: Python Script - Not authorized to send Apple events to C

When I type in the command:
indigo-host -x '/Users/Rick/Scripts/iCal Holiday.py'

I get the following error:
write() argument must be str, not bytes

Rick

Rick

Posted on
Fri Jan 20, 2023 11:16 am
jay (support) offline
Site Admin
User avatar
Posts: 18224
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Python Script - Not authorized to send Apple events to C

Doh, forgot about that bug (which will be fixed in the next release).

Try this instead:

  1. Open a terminal window
  2. Enter the following command:
    Code: Select all
    cd "/Library/Application Support/Perceptive Automation/Indigo 2022.1/IndigoPluginHost3.app/Contents/MacOS/"
  3. Enter the following command (substitute the path to your python script):
    Code: Select all
    IndigoPluginHost3 -x /path/to/script.py

Hopefully, that one will prompt you for permission to access the Calendar app.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Fri Jan 20, 2023 12:36 pm
RickStreet offline
Posts: 29
Joined: Jun 30, 2008

Re: Python Script - Not authorized to send Apple events to C

I get the same error

Rick

Posted on
Fri Jan 20, 2023 1:48 pm
jay (support) offline
Site Admin
User avatar
Posts: 18224
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Python Script - Not authorized to send Apple events to C

Yeah, it appears that Apple's security will no longer allow indirect AppleScript executions. That's a shame, but given what appears to be the slow deprecation of AppleScript it doesn't really surprise me. macOS is slowly becoming unsuitable for power users.

I think you'll need to switch things up a bit and use the Indigo Control Script. Then everything is done from the AppleScript. I think you can then run that AppleScript file from the Execute Script action.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Fri Jan 20, 2023 1:53 pm
jay (support) offline
Site Admin
User avatar
Posts: 18224
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Python Script - Not authorized to send Apple events to C

I've just identified a workaround: create an Action Group with a single Execute Script action in it. Point the action to your AppleScript (not the python script). Run the action group, and you should get prompted twice to allow Calendar scripting. I believe that should flip all the appropriate authentication flags so that your original solution will work.

[MODERATOR NOTE]: have I said recently how much I hate the direction of macOS? :roll:

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Fri Jan 20, 2023 2:36 pm
RickStreet offline
Posts: 29
Joined: Jun 30, 2008

Re: Python Script - Not authorized to send Apple events to C

I checked with ls that I was in the correct t dir: IndigoPluginHost3

used command:
IndigoPluginHost3 -x '/Users/Rick/Scripts/iCal Holiday.py'

got error:
-bash: IndigoPluginHost3: command not found

Rick

Posted on
Fri Jan 20, 2023 2:37 pm
RickStreet offline
Posts: 29
Joined: Jun 30, 2008

Re: Python Script - Not authorized to send Apple events to C

I'll give it a try, thanks!

Rick

Posted on
Fri Jan 20, 2023 2:43 pm
RickStreet offline
Posts: 29
Joined: Jun 30, 2008

Re: Python Script - Not authorized to send Apple events to C

That worked! Thanks a bunch!

Rick

Rick

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 7 guests