SplashBuddy icon indicating copy to clipboard operation
SplashBuddy copied to clipboard

Keep the machine from sleeping.

Open pnbahry opened this issue 7 years ago • 10 comments

I am hoping there is an option to keep the machine from going to sleep while splash buddy is active.

pnbahry avatar Dec 10 '17 23:12 pnbahry

hmmm... I would think adding a line in the code like caffeinate -d -i -m -u & then upon completion kill it ?

killahquam avatar Dec 11 '17 19:12 killahquam

We could probably use this https://developer.apple.com/library/content/releasenotes/Darwin/RN-IOKitPowerManagment/

But I would be surprised it would work in a sandboxed app!

ftiff avatar Dec 11 '17 20:12 ftiff

this is (I believe) the current way: https://developer.apple.com/library/content/qa/qa1340/_index.html

scriptingosx avatar Dec 13 '17 14:12 scriptingosx

I ended up using:

caffeinate -d -i -m -u &

then killing the process, this has worked well for me.

Thanks for all the comments :)

pnbahry avatar Dec 13 '17 21:12 pnbahry

You could also let caffeinate execute the process:

$ caffeinate -dimsu /path/to/executable

will maintain the assertions until the executable ends. Should save a few lines of code.

scriptingosx avatar Dec 14 '17 08:12 scriptingosx

Hi All I am struggling with the Sleep/ScreenSaver. During my deployments it activates the screensaver. And Locks my screen. I want to fix this with the Caffeinate (or any other way). But can somebody help me to add Caffeinate to the SplashBuddy.lunch.sh script? I tryed it. But it did not work for me. Would be great to suspend the screensaver with this Caffeinate tool. Thanks for your help.

#!/bin/bash

# This file should be called by a LaunchAgent
# Its goal is to ensure SplashBuddy only executes when user is on the desktop.

# I suggest you create a Policy to Remove and uninstall the LaunchAgent
# We cannot do it here as LaunchAgent are executed by the user.


loggedInUser=$(/usr/bin/python -c 'from SystemConfiguration import SCDynamicStoreCopyConsoleUser; import sys; username = (SCDynamicStoreCopyConsoleUser(None, None, None) or [None])[0]; username = [username,""][username in [u"loginwindow", None, u""]]; sys.stdout.write(username + "\n");')


app="/Library/Application Support/SplashBuddy/SplashBuddy.app"
doneFile="/Users/${loggedInUser}/Library/Containers/io.fti.SplashBuddy/Data/Library/.SplashBuddyDone"


# Check if:
# - SplashBuddy is not already running
# - SplashBuddy is signed (is fully installed)
# - User is in control (not _mbsetupuser)
# - User is on desktop (Finder process exists)
# - Done file doesn't exist

function appInstalled {
    /usr/bin/codesign --verify "${app}" && return 0 || return 1
}

function appNotRunning {
    /usr/bin/pgrep SplashBuddy && return 1 || return 0
}

function finderRunning {
    /usr/bin/pgrep Finder && return 0 || return 1
}

if appNotRunning \
	&& appInstalled \
	&& [ "$loggedInUser" != "_mbsetupuser" ] \
	&& finderRunning \
	&& [ ! -f "${doneFile}" ]; then

    /usr/bin/open -a "$app"
	
fi

exit 0

joostvanderzwaan avatar Jan 03 '19 10:01 joostvanderzwaan

( We should probably implement it in code https://developer.apple.com/library/archive/qa/qa1340/_index.html )

ftiff avatar Jan 03 '19 14:01 ftiff

( We should probably implement it in code https://developer.apple.com/library/archive/qa/qa1340/_index.html )

Would be great to add this code in new version 👍

joostvanderzwaan avatar Jan 07 '19 09:01 joostvanderzwaan

Got some working on while testing requires both import IOKit and import IOKit.pwr_mgt You call the function like this: self.disableScreenSleep(reason: "Installing required applications." Will work on implementing this into SplashBuddy.

    var assertionID: IOPMAssertionID = 0
    var success: IOReturn?
    
    func disableScreenSleep(reason: String = "Unknown reason") -> Bool? {
        //guard success != nil else { return nil }
        success = IOPMAssertionCreateWithName( kIOPMAssertionTypeNoDisplaySleep as CFString,
                                               IOPMAssertionLevel(kIOPMAssertionLevelOn),
                                               reason as CFString,
                                               &assertionID )
        return success == kIOReturnSuccess
    }
    
    func  enableScreenSleep() -> Bool {
        if success != nil {
            success = IOPMAssertionRelease(0)
            success = nil
            return true
        }
        return false
    }

cybertunnel avatar Feb 01 '19 23:02 cybertunnel

Changing /usr/bin/open -a "$app"

to /usr/bin/caffeinate -dimsu "/Library/Application Support/SplashBuddy/SplashBuddy.app/Contents/MacOS/SplashBuddy"

worked for me

exxille avatar Aug 21 '19 17:08 exxille