Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using iCalBuddy in a cron process #5

Open
edasque opened this issue Jul 18, 2014 · 9 comments
Open

Using iCalBuddy in a cron process #5

edasque opened this issue Jul 18, 2014 · 9 comments

Comments

@edasque
Copy link

edasque commented Jul 18, 2014

I have a quick question about iCalBuddy I couldn’t find a response for in the docs

I have icalbuddy installed in /usr/local/bin and it works flawlessly from command line:

/usr/local/bin/icalBuddy -ea -tf "%H:%M" -b "" -li 4 -n -eed -npn -nc -ps "/ | /" -eep "location,notes,attendees” eventsToday

When I first ran it, if I recall, it asked me to give it access to my calendars which I did. No problem here. This is on Mavericks by the way.

However when I run it from the cron, I see this error in the system.log:

Jul 18 09:37:34 EDASQUEMAC1 icalBuddy[47140]: SecOSStatusWith error:[-34018] The operation couldn’t be completed. (OSStatus error -34018 - Remote error : The operation couldn‚Äôt be completed. (OSStatus error -34018 - client has neither application-identifier nor keychain-access-groups entitlements))

In the error stream for iCalBuddy I see:

2014-07-18 09:14:01.632 icalBuddy[38807:d07] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '* +[CalCalendarStore eventPredicateWithStartDate:endDate:calendars:]: calendars is nil'
*** Call stack at first throw:
(
0 CoreFoundation 0x96274471 __raiseError + 193
1 libobjc.A.dylib 0x909b8091 objc_exception_throw + 162
2 CoreFoundation 0x9627438b +[NSException raise:format:] + 139
3 CalendarStore 0x0002b5e6 +[CalCalendarStore eventPredicateWithStartDate:endDate:calendars:] + 260
4 icalBuddy 0x00005f93 getEvents + 611
5 icalBuddy 0x0000624c getCalItems + 172
6 icalBuddy 0x00002609 main + 1257
7 icalBuddy 0x00002075 start + 53
)

It seems that iCalBuddy when ran from cron from the same user requires some permission that it doesn’t have. Any idea on how to fix this?

@edasque edasque changed the title Using iCalBuddy through a cron process Using iCalBuddy in a cron process Jul 19, 2014
@ali-rantakari
Copy link
Owner

The SecOSStatusWith in the system log is probably a red herring, and not related to this issue. The crash due to missing calendars seems to be the real issue.

I suggest you try using launchd (see man launchctl) instead, with a user-specific launch agent configuration in ~/Library/LaunchAgents.

@edasque
Copy link
Author

edasque commented Jul 23, 2014

Why would it work when launch interactively though?

@rvnd
Copy link

rvnd commented Sep 18, 2014

I got the same error when trying to set up a cron job for this. I can confirm that launchd works.

@coljac
Copy link

coljac commented May 21, 2015

Is this the same as the issue I am facing where icalBuddy will not work headless? If I ssh into my machine, invoking icalBuddy results in "error: No calendars". It works fine from a shell opened directly on the machine.

@knu
Copy link

knu commented Feb 16, 2021

Same for me. Invoking icalBuddy via launchd didn't work either, but I found an easy way out.

  • Open Automator and create a new application that executes a shell script that calls icalBuddy
  • Save it as an application (typically in ~/Applications)
  • Open the application manually and grant access to Calendars and Reminders if asked
  • Add a line to your crontab via crontab -e that goes open -g ~/Applications/YourApp.app
    • Alternatively, you could run it via launchd by writing up a plist file and register it with launchctl load.

@jpm
Copy link

jpm commented Mar 10, 2022

@knu Holy crap, that's the trick to make the damn thing work on a cron process. Legend!

@bburgess19
Copy link

Commenting here to let you know this workaround works for Ventura 13.2.1! @knu you're a monster thank you so much. Also, it turns out I didn't even need to call the app I created from within the crontab—just allowing the permissions once (which in my case, Automator only asked for Documents access) made calling my original script from the crontab work. Afterwards, I could even remove those permissions within Settings > Privacy & Security and it still worked.

@HarshalRohit
Copy link

Hey @bburgess19.
Could you please elaborate a bit more?
Q1: You did not add a cronjob for that .app you created from Automator?
Q2: After creating the .app using Automator, you just added a cronjob for your script (the one you had added in the .app)?

I assumed above two points, and tried something similar but did not work for me.

My end goal is to periodically save the output of icalBuddy in a file, which will later be used in other workflow using python.
Any suggestions around this?

@bburgess19
Copy link

@HarshalRohit
Q1: No I never added the .app to the crontab, just the script which uses icalbuddy.
Q2: Related to Q1^

I basically only followed the instructions until manually opening the .app, at which point it asked for permissions to my Documents folder. Once I granted them, my script ran as expected through cron. Hope this helps, and sorry for the tricky troubleshooting!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants