0
我有一個腳本:你可以在if else語句中重複嗎?
property firstRow : 2090
property lastRow : 5584
set r to firstRow
-- highly recommended
-- close all of Safari's windows before...
tell application "Safari"
close windows
end tell
-- loop through the given row numbers
repeat until r is (lastRow + 1)
-- get the search value for Safari auto completion (column J)
tell application "Microsoft Excel"
tell active sheet
set searchTerm to string value of range ("J" & r) of active sheet
set searchTerm1 to string value of range ("J" & r-1) of active sheet
if searchTerm1=searchTerm then
set r to r + 1
end tell
end tell
end repeat
else
set searchTerm to searchTerm1
end if
end tell
end tell
-- open Safari and make a new window
tell application "Safari"
activate
make new document with properties {URL:""}
delay 0.5
set pageLoaded to false
end tell
-- type the search value into the address field and hit return (aka select and open the first proposal)
tell application "System Events"
-- here with Safari 6.1 text field 1 of group 2 of tool bar 1 of window 1 points to the URL field
set focused of text field 1 of group 2 of toolbar 1 of window 1 of process "Safari" to true
delay 0.5
keystroke searchTerm
delay 1.5
keystroke return
end tell
-- let open Safari the suggested web page and read out the finally used URL
tell application "Safari"
repeat while not pageLoaded -- keep doing this loop until loading complete
delay 5
if (do JavaScript "document.readyState" in document 1) is "complete" then
set pageLoaded to true
else
-- not sure if this second else is needed, why not just wait until the first access has finished...
-- close document 1
-- make new document with properties {URL:""}
-- tell application "System Events"
-- delay 1.5
-- set focused of text field 1 of group 2 of tool bar 1 of window 1 of process "Safari" to true
-- delay 1.5
-- keystroke searchTerm
-- delay 1.5
-- keystroke return
-- end tell
end if
set thisULR to "NO SITE"
end repeat
try
set thisURL to URL of document 1
on error
set thisURL to "NO SITE"
end try
close document 1
end tell
-- write the result into the cell next to the key word (column K)
tell application "Microsoft Excel"
if thisURL then
tell active sheet
make new hyperlink of cell ("K" & r) with properties {address:thisURL, name:thisURL}
end tell
else
tell active sheet
make new cell ("K" & r) with properties {name:"NO SITE"}
end tell
end if
end tell
set r to r + 1
end repeat
它基本上作品除了第一,如果再else語句。我希望我在這裏做的事情很清楚。我對applescript很新,非常感謝你的幫助。如果發生這種情況,我試着去做,然後用下一個r值重新啓動腳本,但是如果沒有,那就繼續腳本。
謝謝。但是如果我寫退出重複,那麼不會不會重複更高的r值?我希望它重複使用新的r值,而不是用舊的r值繼續執行腳本的其餘部分。 – Dan 2014-11-03 23:53:22