Last active
July 3, 2020 16:22
-
-
Save pdehlke/9573147 to your computer and use it in GitHub Desktop.
Applescript to turn off interruptions whenever you're in a meeting
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Run via crontab: 0,1,29,30,31,59 8-18 * * 1,2,3,4,5 osascript /Users/pdehlke/bin/icalMeeting.scpt | |
tell application "System Events" to set AdiumIsRunning to (count of (every process whose name is "Adium")) > 0 | |
tell application "System Events" to set SkypeIsRunning to (count of (every process whose name is "Skype")) > 0 | |
tell application "System Events" to set OutlookIsRunning to (count of (every process whose name is "Microsoft Outlook")) > 0 | |
set curdate to current date | |
set tomorrow to (current date) + 86400 | |
tell application "Calendar" | |
set theCalendarNames to title of every calendar | |
set calsToDelete to {"Birthdays", "US Holidays"} | |
set calsToCheck to {} | |
repeat with i from 1 to number of items in theCalendarNames | |
if {item i of theCalendarNames} is not in calsToDelete then set calsToCheck's end to item i of theCalendarNames | |
end repeat | |
repeat with i from 1 to number of items in calsToCheck | |
set curCal to item i of calsToCheck | |
tell calendar curCal | |
set theEventList to (every event whose (start date < (curdate)) and (end date > (curdate)) and (allday event = false) and (end date < (tomorrow))) | |
end tell | |
end repeat | |
end tell | |
if number of items in theEventList > 0 then | |
-- I'm in a meeting, so quiet down | |
--Turn off the notification center | |
do shell script "launchctl unload -w /System/Library/LaunchAgents/com.apple.notificationcenterui.plist 2> /dev/null" | |
if OutlookIsRunning then | |
tell application "Microsoft Outlook" | |
set display alerts to false | |
end tell | |
end if | |
if AdiumIsRunning then | |
tell application "Adium" | |
go invisible | |
-- quit | |
end tell | |
end if | |
if SkypeIsRunning then | |
tell application "Skype" | |
send command "SET USERSTATUS INVISIBLE" script name "My Script" | |
end tell | |
end if | |
tell application "Messages" | |
set status to offline | |
end tell | |
return | |
else | |
-- I'm not in a meeting, so tell me things | |
-- Turn on the notification center | |
do shell script "launchctl load -w /System/Library/LaunchAgents/com.apple.notificationcenterui.plist 2> /dev/null" | |
if OutlookIsRunning then | |
tell application "Microsoft Outlook" | |
set display alerts to true | |
end tell | |
end if | |
if AdiumIsRunning then | |
tell application "Adium" | |
go available | |
end tell | |
end if | |
if SkypeIsRunning then | |
tell application "Skype" | |
send command "SET USERSTATUS ONLINE" script name "My Script" | |
end tell | |
end if | |
tell application "Messages" | |
set status to available | |
end tell | |
return | |
end if | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment