Je voudraisPerform certains événements système, Mac OS X
- arrêt
- Restart
- Logoff
- sommeil
Mon système grâce à une application que je fais, Je n'arrive pas à trouver un moyen natif de l'Objective C de le faire et c'est vraiment difficile.
Quelqu'un peut-il me guider sur la meilleure façon de le faire:
J'ai essayé:
NSString *scriptAction = @"restart"; // @"restart"/@"shut down"/@"sleep"/@"log out"
NSString *scriptSource = [NSString stringWithFormat:@"tell application \"Finder\" to %@", scriptAction];
NSAppleScript *appleScript = [[[NSAppleScript alloc] initWithSource:scriptSource] autorelease];
NSDictionary *errDict = nil;
if (![appleScript executeAndReturnError:&errDict]) {
//
}
qui avait pas de chance du tout, essayé aussi:
NSAppleScript* theScript = [[NSAppleScript alloc] initWithSource:
@"Tell application \"Finder\" to restart"];
if (theScript != NULL)
{
NSDictionary* errDict = NULL;
// execution of the following line ends with EXC
if (YES == [theScript compileAndReturnError: &errDict])
{
[theScript executeAndReturnError: &errDict];
}
[theScript release];
}
Sans chance
duplication possible de [Shutdown Mac Objective C] (http://stackoverflow.com/questions/4505632/shutdown-mac-objective-c) –
La question technique 1134 devrait vous être utile: http://developer.apple.com /library/mac/#qa/qa1134/_index.html –
Hi Josh. J'ai posté la première question en fait. Totalement oublié à ce sujet. J'ai essayé toutes les méthodes énumérées y compris le q & a un sans la chance –