Is there some kind of script or automation I can run that gives me the possibility for certain apps to open at login but only on certain days? For instance I want to be able to open Mail, Slack, Notion and Zoom automatically on weekdays but not on weekends. It's not a major issue but it would be nice. Thanks!
2 Answers
There are a couple of ways to approach this, but they require removing the items from Login items and kicking them off a different way. Here are your options:
Use AppleScript. You would replace your Login items with a single AppleScript that checks the day of the week and launches the applications appropriately. It’s not too tricky to accomplish this. Here are some excellent links that can get you started:
Use a LaunchAgent managed by
launchd
(my preferred method). You wouldn’t use Login Items for any of these apps. Though a bit more complex than an AppleScript (IMO), it gives you more granular control as every App becomes, in essence a service that you can individually control.This is an excellent post, launchd plist format for running a command at a specific time on a weekday, that details how to create the .plist and in which directory you would place it in to achieve your desired results (
~/Library/LaunchAgents
would closely mimic the Login Items function). Also see Is it possible to allow usage for an app or program for a specific times on a Mac?, it’s about allowing apps to only run on certain days (so, ignore the Gatekeeper portion), but provides an excellent example how to structure the .plist for day specific actions.
Paste this following AppleScript code into a new Script Editor.app document and run the code to test that works then save it as an .app.
Then just go to System Preferences and add your new .app to the Login Items.
property theWeekdays : {"Monday", "Tuesday", "Wednesday", "Thursday", "Friday"}
property theApps : {"Mail", "Slack", "Notion", "Zoom"}
set currentWeekday to weekday of (get current date) as text
if currentWeekday is in theWeekdays then
repeat with thisApp in theApps
try
tell application thisApp to activate
end try
delay 10
end repeat
end if