可能重复:
How do I scroll to the top of a window using applescript?
我想在Mac OS X 10.6上控制其他进程的其他窗口。
例如,我想向下滚动Safari。
我该怎么做?
答案 0 :(得分:1)
AppleScript可以在Safari中向下滚动页面,检查:
How do I scroll to the top of a window using applescript?
脚本:
tell application "System Events"
tell application "Safari" to activate
delay 0.5
key code 119
end tell
只需使用NSAppleScript运行此脚本:
NSAppleScript *scrollDownSafari = [[NSAppleScript alloc] initWithSource:@"tell application \"System Events\"\ntell application \"Safari\" to activate\ndelay 0.5\nkey code 119\nend tell"];
[scrollDownSafari executeAndReturnError:nil];
修改强>
更好的可读代码:
NSString *script =
@"tell application \"System Events\"\n"
"tell application \"Safari\" to activate\n"
"delay 0.5\n"
"key code 119\n"
"end tell";
NSAppleScript *scrollDownSafari = [[NSAppleScript alloc] initWithSource:script];
[scrollDownSafari executeAndReturnError:nil];