简体   繁体   中英

How to run bash script on wake mac os x

Want to change Wi-Fi settings on wake (osx).

I have script for that but don't want to run it manually every time.

Is there any way to run it on wake?

Maybe this will help you out:

Running script upon login mac [closed]

This functionality of running script after waking up can be achieved with the powerful hammerspoon :

function printf(s,...)  print(s:format(...)) end
wather = hs.caffeinate.watcher.new(function(eventType)    
    -- screensDidWake, systemDidWake, screensDidUnlock
    if eventType == hs.caffeinate.watcher.systemDidWake then
        local output = hs.execute("/bin/echo -n hello", false)
        hs.notify.new({title="TestTitle", informativeText=output}):send()
        printf("%s, world", output)
    end
end)
wather:start()

Put those script to $HOME/.hammerspoon/init.lua and reload hammerspoon, and you can check the above /bin/echo output in the hammerspoon console.
There are several wake up events, including screensDidWake , systemDidWake , screensDidUnlock . See wather api doc for details.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM