I am using this test script to test out whether you can actually hold down a key for any specified time.
I have two problems. I believe the “key down” command can do this but maybe I am not using it correctly and when specifying a key that doesn’t have a letter or number, what do you call it ie “left arrow”, “right arrow”…
i’m trying to get a safari browser to scroll down smoothly.
It appears this script just jumps down.
any suggestions?
tell application "Finder"
set frontmost of process "Safari" to true
end tell
tell application "System Events"
key down "down arrow"
delay 3
key up "down arrow"
end tell
Untested but I would expect your script would look like this.
tell application "Safari"
activate
tell application "System Events"
tell process "Safari"
key down (ASCII character 31) -- Down arrow
delay 3
key up (ASCII character 31) -- Down arrow
end tell
end tell
end tell
I think both of these work. It’s clear that they key is working since I can see the browser jump down.
I’m not sure this command though will hold the key down.
Anybody know for sure?
Even though my math is wrong, this feels like one second…
tell application "Safari"
activate
tell application "System Events"
tell process "Safari"
repeat 30 times -- repeat 50 times -- feels like 3 seconds
key down (ASCII character 31) -- Down arrow
delay 1.0E-4
end repeat
key up (ASCII character 31) -- Down arrow
end tell
end tell
end tell
As seen as you are using system events you may also want to try using the increment arrows this quick test worked just fine in a basic test for me.
tell application "Safari"
activate
open location "http://bbs.macscripter.net/viewtopic.php?id=27688"
end tell
-- Wait until page loaded
if page_loaded(5) is false then return
--
tell application "System Events"
tell process "Safari"
tell window 1
if exists group 3 then
tell group 3
tell scroll area 1
tell scroll bar 1
set Page_End to false
repeat until Page_End is true
delay 0.5
set x to get size of button 3
set y to item 2 of x
if y = 0 then set Page_End to true
click button 1
end repeat
end tell
end tell
end tell
end if
end tell
end tell
end tell
--
on page_loaded(timeout_value)
delay 2
repeat with i from 1 to the timeout_value
tell application "Safari"
if (do JavaScript "document.readyState" in document 1) is "complete" then
return true
else if i is the timeout_value then
return false
else
delay 1
end if
end tell
end repeat
return false
end page_loaded
This script is also not exactly what I was trying to do. I was trying to use the arrow down key to use in a script to enable the 1x, 2x or 3x fast forward in the apple remote.
It was just easier to test out in a safari browser page.