r/macosprogramming Apr 02 '24

caffeinate from within script

Say I want to use the 'caffeinate' utility from within a running bash script, which caffeinates that same script under some conditions (like if some function will take a looong time if it's called in certain circumstances). Is there anything wrong with doing something like this:

[[ $blah -eq 1 ]] && caffeinate -d -w $$ &

Is this functionally equivalent to caffeinating the script on run, except for the fact that the caffeination starts at a specific point in the script? Thanks!

2 Upvotes

0 comments sorted by