0

I'm trying to get today's events from Calendar.app in Hammerspoon.

I have the following Javascript, that works well in the Script Editor:

enter image description here

But, if I paste this in a call to hs.osascript.javascript(), like this:

local source = [[
var Calendar = Application("Calendar")

var startDate = new Date
startDate = startDate
startDate.setHours(0)
startDate.setMinutes(0)
startDate.setSeconds(0)
var endDate = new Date
endDate.setHours(23)
endDate.setMinutes(59)
endDate.setSeconds(59)

var projectCalendars = Calendar.calendars.whose({name: "MyCal"})
var projectCalendar = projectCalendars[0]
var events = projectCalendar.events.whose({startDate: {_greaterThan: startDate}, endDate: {_lessThanEquals: endDate}})
var event = events[0]
event().summary()
]]

print("yyy", hs.osascript._osascript(source, "JavaScript"))

This produces the following error:

yyy false   nil {
    NSLocalizedDescription = "Error: Error: An error occurred.";
    NSLocalizedFailureReason = "Error: Error: An error occurred.";
    OSAScriptErrorBriefMessageKey = "Error: Error: An error occurred.";
    OSAScriptErrorMessageKey = "Error: Error: An error occurred.";
    OSAScriptErrorNumberKey = "-1743";
    OSAScriptErrorRangeKey = "NSRange: {0, 0}";
}

Using hs.osascript.javascript produces the same behavior.

I'm not sure what I'm doing wrong here. Can someone advise please? I'm running Big Sur.

sharat87
  • 7,330
  • 12
  • 55
  • 80

0 Answers0