Follow

I got so sick of my Mac crashing any time it slept while connected to a display that I wrote some Ruby to fix it!

```
#!/usr/bin/env ruby

time_to_wait = ARGV[0].to_i

loop do
display_attached = `system_profiler SPDisplaysDataType | grep "Thunderbolt Display"`.chomp.length > 0

if display_attached
puts "#{Time.now} - Detected external display: instructing computer to not idle-sleep to avoid crashing, for #{time_to_wait} seconds"

`caffeinate -i -t #{time_to_wait}`
else
puts "#{Time.now} - No display detected. Sleeping for #{time_to_wait} seconds"

sleep time_to_wait
end
end
```

Sign in to participate in the conversation
Ruby.social

A Mastodon instance for Rubyists & friends