2011-11-07 46 views
3

我需要以編程方式更改「系統偏好設置>鍵盤>修飾鍵」中的大寫鎖定,控制,選項和命令鍵的值。 ..「如何更改「系統偏好設置>鍵盤>修飾鍵...」

我不想使用AppleScript。

難道有人指着我正確的方向嗎?

+0

我想如果你可以通過AppleScript來做到這一點,那麼你可以通過可可代碼執行相同的命令;) – Devarshi

+1

是的,但是如何:0。 –

+1

我需要回答相同的問題,但我不在乎它的AppleScript或其他。我只需要這樣做。你有沒有找到答案 – MarqueIV

回答

0

這裏是蘋果腳本帽LockOff.scpt:

tell application "System Preferences" 
    activate 
    set current pane to pane "com.apple.preference.keyboard" 
end tell 

tell application "System Events" 

    tell application process "System Preferences" 
     get properties 

     click button "Modifier Keys…" of tab group 1 of window "Keyboard" 
     tell sheet 1 of window "Keyboard" 
      click pop up button 4 
      click menu item "No Action" of menu 1 of pop up button 4 
      delay 1 
      click button "OK" 

     end tell 
    end tell 
end tell 

tell application "System Preferences" to quit 

以下是調用上述腳本的可可代碼。希望這會有所幫助

-(void)runAppleScript{ 

    NSString *fileName = @"capsLockOff"; 

    NSString* path = [[NSBundle mainBundle] pathForResource:fileName ofType:@"scpt"]; 
    NSURL* url = [NSURL fileURLWithPath:path];NSDictionary* errors = [NSDictionary dictionary]; 
    NSAppleScript* appleScript = [[NSAppleScript alloc] initWithContentsOfURL:url error:&errors]; 
    [appleScript executeAndReturnError:nil]; 
    [appleScript release]; 
} 
1

正如我在評論中建議:

我認爲,如果你能夠通過AppleScript的做到這一點,那麼你就可以執行通過可可代碼 相同的命令;)

可以將此文件指這樣做的:Using AppleScript Scripts in Cocoa Applications

希望這有助於:)

+0

我不想使用AppleScript,因爲用戶會意識到它。 –

+0

如果我將使用AppleScript - 蘋果是否會在Mac App Store上的程序中使用它? –

+0

@Miraaj,你剛剛鏈接到蘋果的開發人員使用腳本的文檔(順便說一句,你的鏈接似乎已經死了。)你有關於這個特定問題的任何信息,而不僅僅是通用腳本? – MarqueIV