2012-07-27 21 views
1

是否有任何(App Store安全)方式自動用文本填充另一個應用程序的第一響應者文本字段?例如,使用由NSStatusBar應用程序指定的熱鍵,用戶在單獨的應用程序中突出顯示文本(如TextEdit),並將新文本粘貼到狀態欄應用程序根據情景數據生成的TextEdit中。「粘貼」文本到外部Mac應用程序第一響應者

回答

2

是否有任何方式自動填充文本的另一個應用程序的第一響應文本字段?

是,收銀臺下面的AppleScript:

tell application "System Events" to keystroke "Hello World" 

使用NSTask從Objective-C的運行:

NSString *theText = @"Hello World"; 
NSString *theSource = [NSString stringWithFormat:@"tell application \"System Events\" to keystroke \"%@\"",theText]; 
NSAppleScript *theScript = [[NSAppleScript alloc] initWithSource:theSource]; 
[theScript executeAndReturnError:nil]; 

注意,腳本需要輔助設備的訪問:

系統首選項→通用訪問→啓用訪問輔助設備

使用上述代碼的應用程序不會被Apple拒絕。

+0

很好,謝謝! – daltonclaybrook 2012-07-27 23:50:25

+0

如果沒有特定的目標應用程序例外授權,我認爲這不再起作用。 – Crutt 2017-01-02 21:00:13

相關問題