简体   繁体   中英

If next item exists in list, then applescript

This is my first Applescript. I want to be able to account for as many items as possible using a loop that will move on to the next step when there are no more additional elements in the list. My version now only accounts for two text items. Thank you in advance!

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

Thank you so much!

You can use a repeat with loop:

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

See AppleScript Language Guide: Control Statements Reference .

open location doesn't open a New Tab page:

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

You could also run something like this in Terminal:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM