ali-rantakari / icalBuddy

Command-line utility for printing events and tasks from the OS X calendar database.
149 stars 33 forks source link

Using iCalBuddy in a cron process #5

Open edasque opened 10 years ago

edasque commented 10 years ago

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?

ali-rantakari commented 10 years ago

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 commented 10 years ago

Why would it work when launch interactively though?

rvnd commented 9 years ago

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

coljac commented 9 years ago

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 commented 3 years ago

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

jpm commented 2 years ago

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

bburgess19 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

@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!