Skip to content

Instantly share code, notes, and snippets.

@barretts
Last active May 23, 2025 18:01
Show Gist options
  • Save barretts/ecc60d68a92139fe0aa13591e4d9dc42 to your computer and use it in GitHub Desktop.
Save barretts/ecc60d68a92139fe0aa13591e4d9dc42 to your computer and use it in GitHub Desktop.
automatically open meeting links for calendar events in the next 5 minutes using Hammerspoon
local lastOpenedLink = nil
local lastOpenedTime = 0
function openMeetingLink(link)
local now = os.time()
if link and (link ~= lastOpenedLink or now - lastOpenedTime > 600) then
hs.urlevent.openURL(link)
lastOpenedLink = link
lastOpenedTime = now
else
if link then
hs.printf("skipped double open of url %s", link)
else
hs.printf("why am i here if no link")
end
end
end
local function checkCalendarForMeetingLinks()
hs.printf("%s CalendarLi: Checking calendar events...", os.date("%H:%M:%S"))
local script = [[
set matchingEvents to {}
set now to (current date)
set fiveMinutesFromNow to now + (5 * minutes)
tell application "Calendar"
repeat with cal in calendars
set theEvents to (every event of cal whose start date ≥ now and start date ≤ fiveMinutesFromNow)
repeat with e in theEvents
set summaryText to summary of e
set descriptionText to description of e
set end of matchingEvents to (summaryText & "||" & descriptionText)
end repeat
end repeat
end tell
return matchingEvents
]]
local success, result, _ = hs.osascript.applescript(script)
if success and result then
hs.printf("AppleScript returned %d events", #result)
for i, entry in ipairs(result) do
local summary, description = string.match(entry, "^(.-)%|%|(.*)$")
hs.printf("Event #%d:", i)
hs.printf(" Summary: %s", summary or "(nil)")
hs.printf(" Description: %s", description or "(nil)")
local link = string.match(description or "", "https?://[%w./%-_=?&]+")
if link then
hs.printf(" Opening link: %s", link)
openMeetingLink(link)
break
end
end
else
hs.printf("AppleScript failed or returned no results")
end
end
-- Run every 1 minute
hs.timer.doEvery(60, checkCalendarForMeetingLinks)
hs.printf("%s CalendarLi: Calendar meeting link auto-opener started.", os.date("%H:%M:%S"))
checkCalendarForMeetingLinks()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment