Skip to content
This repository has been archived by the owner on Feb 8, 2023. It is now read-only.

Keep the machine from sleeping. #59

Open
pnbahry opened this issue Dec 10, 2017 · 10 comments
Open

Keep the machine from sleeping. #59

pnbahry opened this issue Dec 10, 2017 · 10 comments
Assignees
Labels

Comments

@pnbahry
Copy link

pnbahry commented Dec 10, 2017

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

@killahquam
Copy link

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

@ftiff
Copy link
Collaborator

ftiff commented Dec 11, 2017

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!

@scriptingosx
Copy link
Contributor

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

@pnbahry
Copy link
Author

pnbahry commented Dec 13, 2017

I ended up using:

caffeinate -d -i -m -u &

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

Thanks for all the comments :)

@scriptingosx
Copy link
Contributor

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.

@joostvanderzwaan
Copy link

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

@ftiff
Copy link
Collaborator

ftiff commented Jan 3, 2019

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

@joostvanderzwaan
Copy link

(
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 👍

@cybertunnel
Copy link
Collaborator

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 cybertunnel self-assigned this Feb 1, 2019
@exxille
Copy link

exxille commented Aug 21, 2019

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

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

worked for me

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

7 participants