Created
June 6, 2016 19:51
-
-
Save stephanschulz/bccfb2f3f7ebb9bdebcfcbcc7a372a19 to your computer and use it in GitHub Desktop.
check system preferences scheduled shutdown time and exit OF app just before
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//-------------------------------------------------------------- | |
void ofApp::setup(){ | |
string path = "/Library/Preferences/SystemConfiguration/com.apple.AutoWake.plist"; | |
ofFile file; | |
file.open(path); // open a file | |
ofBuffer buffer = file.readToBuffer(); // read to a buffer | |
// ofXml XML; | |
// XML.loadFromBuffer( buffer.getText() ); // now get the buffer as a string and make XML | |
string bufferString = buffer.getText(); | |
bool found_RepeatingPowerOff = false; | |
bool got_powerOffTime = false; | |
int shutDownMinutes = -1; | |
if(buffer.size()) { | |
// for (ofBuffer::Line it = buffer.getLines().begin(), end = buffer.getLines().end(); it != end; ++it) { | |
while(buffer.isLastLine() == false) { | |
string line = buffer.getNextLine(); | |
// copy the line to draw later | |
// make sure its not a empty line | |
if(line.empty() == false) { | |
if(ofIsStringInString(line,"<key>RepeatingPowerOff</key>")){ | |
ofLog()<<"found_RepeatingPowerOff"; | |
found_RepeatingPowerOff = true; | |
} | |
if(found_RepeatingPowerOff && ofIsStringInString(line, "integer")){ | |
ofStringReplace(line,"<integer>",""); | |
ofStringReplace(line,"</integer>",""); | |
ofLog()<<"time in min "<<line; | |
shutDownMinutes = ofToInt(line); | |
got_powerOffTime = true; | |
break; | |
} | |
} | |
// print out the line | |
// cout << line << endl; | |
} | |
} | |
if(shutDownMinutes == -1){ | |
ofLog()<<"not shutdown time is set in "<<path; | |
}else{ | |
ofLog()<<"shutDownTime "<<shutDownMinutes; | |
int currentMinutes = ofGetHours()*60 + ofGetMinutes(); | |
ofLog()<<"currentMinutes "<<currentMinutes; | |
ofLog()<<"until "<<currentMinutes - shutDownMinutes; | |
} | |
std::exit(1); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment