Is there a way to run programs / open files when the Mac is unlocked from sleeping?

Does anyone know if its possible to get automator to do this?


You can do login items on a Mac but this is when the machine is turned off first.


Is this available when you simply unlock after sleeping.


Any help is appreciated 👍

MacBook, macOS 10.14

Posted on Mar 21, 2019 10:29 AM

Reply
4 replies

Mar 21, 2019 5:02 PM in response to jacknelson260397

Jack, just an update. After tinkering with it for a few hours, I have some GOOD NEWS!


I now have the "SleepWatcher" daemon successfully installed, working in conjunction with a launchd job and a shell script. Actually, there are two shell scripts: one to shut down apps at sleep time, and a second one to launch apps at wakeup time. You can add as many apps to the scripts as you like. You can even write the scripts in AppleScript if you like. :)


There are other commercial and free apps out there that will do this kind of thing, but it was fun for me to learn how to do this, and to take up the challenge of getting it to work.


If you are interested in setting up "SleepWatcher" on your own machine, please let me know, and I will post very clear instructions here for you.


Take care, my friend! :)

Mar 21, 2019 10:57 AM in response to jacknelson260397

From my research, I have discovered that, yes, there is a way to do this. There is a command line tool called "Sleepwatch".


This daemon monitors sleep, wakeup and idleness of a Mac. It can be used to execute a Unix command when the Mac or the display of the Mac goes to sleep mode or wakes up, after a given time without user interaction or when the user resumes activity after a break or when the power supply of a Mac notebook is attached or detached. It also can send the Mac to sleep mode or retrieve the time since last user activity.


In your case, you can use "SleepWatch" to execute a shell script which will launch your applications. For example, the shell script might look something like the following. I just wrote this script as a simple example. You can even make it clickable by changing the file extension from ".sh" to ".command":



#!/usr/bin/env bash
# =============================================================================
# macOS 10.14.3 (18D109)
# Terminal: Version: 2.9.1 64-Bit (Intel): Yes
# Terminal Location: /Applications/Utilities/Terminal.app
# Time Machine Log Viewer
# =============================================================================

open /Applications/Mail.app /Applications/Firefox.app


I am not exactly sure how you would set up such a script to work with "SleepWatch", being as I didn't look into it too deeply, but it probably isn't too difficult to figure out. In fact, I just looked at the ReadMe, and it pretty much tells you what to do, assuming you understand it. :)


I hope this points you in the right direction. I bet something like this can also be done with Automator, and maybe even with AppleScript -- a.k.a. the Script Editor in the Utilities" folder -- but again, I personally wouldn't know how to do it.


I hope the above helps. Let me know. :)


Mar 21, 2019 11:14 AM in response to jacknelson260397

Jack, if you decide to go the AppleScript route, I just discovered a cheap app on the App Store -- only $5 -- called "Scenario" which will run AppleScripts on sleep, wake, logout, login, etc. This might be more to your liking, if using SleepWatcher in combination with a shell script is too difficult for you. In fact, I am going to try to set up a SleepWatcher event myself, just to see if I can do it. :)

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Is there a way to run programs / open files when the Mac is unlocked from sleeping?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.