1

Cocoa アプリケーションで、コンピューターの画面ロックのタイムアウト設定にアクセスして変更したいと考えています。システム環境設定で変更する場合、ユーザーは管理者パスワードを入力する必要はありません。

システム設定のスクリーンショット - 画面ロックのタイムアウト

残念ながら、ドキュメントに情報が見つかりませんでした。また、どのトピックを調べればよいかわかりません (セキュリティ設定 / prefPane プログラミング)。
どんな助けでも大歓迎です。

4

2 に答える 2

1
NSMutableDictionary* plistDict = [[NSMutableDictionary alloc] initWithContentsOfFile:@"/Users/new/Library/Preferences/com.apple.screensaver.plist"];
[plistDict setObject:@"1" forKey:@"askForPassword"];
[plistDict setObject:@"3600" forKey:@"askForPasswordDelay"];
[plistDict writeToFile:@"/Users/new/Library/Preferences/com.apple.screensaver.plist" atomically:YES];  

またはターミナルから

defaults write com.apple.screensaver askForPasswordDelay 5
于 2012-05-23T12:43:20.193 に答える
1

上記の回答は一部では機能するようですが、10.8 で FileVault を使用している場合は失敗します。設定は保持されますが、システム環境設定を起動するまで実際には有効になりません。幸いなことに、完了後に設定に「触れる」方法があります。

- (void)touchSecurityPreferences;
{
    NSAppleScript *kickSecurityPreferencesScript = [[[NSAppleScript alloc] initWithSource: @"tell application \"System Events\" to tell security preferences to set require password to wake to true"] autorelease];
    [kickSecurityPreferencesScript executeAndReturnError:nil];
}

編集これは、ゼロ以外の設定からゼロ設定に移行する場合にのみ機能することがわかりました。これはセキュリティ上のものだと思います。逆に行くには、システム環境設定を起動するしかありません。

編集2システム環境設定を起動するためのコードは次のとおりです。

- (void)launchAndQuitSecurityPreferences;
{
    // necessary for screen saver setting changes to take effect on file-vault-enabled systems when going from a askForPasswordDelay setting of zero to a non-zero setting
    NSAppleScript *kickSecurityPreferencesScript = [[[NSAppleScript alloc] initWithSource:
                                                     @"tell application \"System Preferences\"\n"
                                                     @"     tell anchor \"General\" of pane \"com.apple.preference.security\" to reveal\n"
                                                     @"     activate\n"
                                                     @"end tell\n"
                                                     @"delay 0\n"
                                                     @"tell application \"System Preferences\" to quit"] autorelease];
    [kickSecurityPreferencesScript executeAndReturnError:nil];
}
于 2013-05-03T23:01:17.240 に答える