如果列表中存在下一个项目,则为applescript

时间:2013-05-21 22:14:23

标签: macos google-chrome url applescript

这是我的第一个Applescript。我希望能够使用循环来考虑尽可能多的项目,当列表中没有其他元素时,循环将继续进行下一步。我的版本现在只占两个文本项。先感谢您!

set userone to text returned of (display dialog "Job IDs Please" default answer "" buttons {"Submit", "Cancel"} default button 1)

set oldDelimiters to AppleScript's text item delimiters
set AppleScript's text item delimiters to " "
set urllist to every text item of userone

set joburl to "http://crowdflower.com/jobs/"
set urlcrowds to urllist
copy urllist to urlcrowds
set item 1 of urlcrowds to joburl & 1st item of urllist
set item 2 of urlcrowds to joburl & 2nd item of urllist

get urlcrowds

tell application "Google Chrome"

activate

make new window

set myTab to make new tab at end of tabs of window 1

set URL of myTab to item 1 of urlcrowds

set myTab to make new tab at end of tabs of window 1

set URL of myTab to item 2 of urlcrowds

close tab 1 of window 1

end tell

非常感谢你!

1 个答案:

答案 0 :(得分:0)

您可以使用循环重复:

set l to {12379081, 3785788, 3351991}
tell application "Google Chrome" to tell (make new window)
    repeat with i in l
        set u to "http://crowdflower.com/jobs/" & i
        make new tab at end of tabs with properties {URL:u}
    end repeat
    close tab 1
end tell

请参阅AppleScript Language Guide: Control Statements Reference

open location无法打开新标签页:

repeat with i in words of "12379081 3785788 3351991"
    open location "http://crowdflower.com/jobs/" & i
end repeat

你也可以在终端中运行这样的东西:

open http://crowdflower.com/jobs/{12379081,3785788,3351991} -a Google\ Chrome