2011-04-19 114 views

回答

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]; 
+0

您可以通过使用字符串连接更加可读:'@ “ab'” 等同于'@ “一个” @ “B”'。 – 2011-04-19 08:57:47

+0

我同意:)注意:只有第一行需要'@',但是你可以在每一行使用'@'。 – Anne 2011-04-19 09:06:26

+0

有没有其他解决方案使用Objective C? – 2011-04-20 00:46:26