1

I am looking to make an Applescript that will take a list of numbers inputted by the user like (copy and pasted just like this):

25082945
25463469
03146331
36584524
23461461

Then, in a browser, open a new tab or each number with the number as the URL.

This is how far I have gotten:

display dialog "Please Enter IDs" with icon caution default answer ""
set id_list to text returned of result

tell application "Google Chrome"
    make new tab at end of tabs of window 1 with properties {URL:id_list}
end tell

I am guessing that I need to filter the input into a list but I heard that Applescript does not register formatting so the line breaks are not registered. Then for each item in the id_list, open new tab, set url as that number.

1 Answer 1

1

If you're copying and pasting a list, as in what's shown in your question, as in lines of text that have the (hidden) newline character at the end of each line, you can use the following:

display dialog "Please Enter IDs" with icon caution default answer ""
set id_list to text returned of result

if id_list is not "" then
    set i to 1
    repeat (count paragraphs in id_list) times
        tell application "Google Chrome"
            make new tab at end of tabs of window 1 with properties {URL:(paragraph i of id_list)}
        end tell
        set i to i + 1
    end repeat
end if

Here's the Event Log in AppleScript Editor after running the AppleScript code above:

tell application "AppleScript Editor"
    display dialog "Please Enter IDs" with icon caution default answer ""
        --> {text returned:"25082945
25463469
03146331
36584524
23461461", button returned:"OK"}
end tell
tell application "Google Chrome"
    make new tab at end of every tab of window 1 with properties {URL:"25082945"}
        --> tab id 8 of window id 1
    make new tab at end of every tab of window 1 with properties {URL:"25463469"}
        --> tab id 11 of window id 1
    make new tab at end of every tab of window 1 with properties {URL:"03146331"}
        --> tab id 14 of window id 1
    make new tab at end of every tab of window 1 with properties {URL:"36584524"}
        --> tab id 17 of window id 1
    make new tab at end of every tab of window 1 with properties {URL:"23461461"}
        --> tab id 20 of window id 1
end tell
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .