It is possible to with the script:

tell application "Safari"
    set urls to URL of every tab of every window
end tell

when execute, get all urls of every tab of every window (two dimensional list)

 {{"http://domain1", "http://domain2", ...}, {"http://domain3", "http://domain4", ...}, {...}}

But is it possible with:

tell application "Safari"
    set (urls & name) to URL of every tab of every window
end tell

to get a record instead of list:

 {{{url: "http://domain1", name: "domain1 - foo"}, {url: "http://domain2", name: "domain2 - bar2"}, {...}}, {{url: "http://domain3", name: "domain3 - foo3"}, {url: "http://domain4", name: "domain4 - bar4"}, {...}}}

Is it possible, or should I use only repeat?

1 Answer 1


It is not possible to get a record with a single object specifier, but you can get a list:

tell application "Safari"
    {URL, name} of tabs of windows
end tell
-- {{{"http://url1", "title 1"}, {"http://url2", "title 2"}}}

For a record, you can use a repeat loop:

set r to {}
tell application "Safari"
    repeat with t in tabs of windows
        set end of r to {|url|:URL of t, |name|:name of t}
    end repeat
end tell
-- {{|url|:"http://url1", |name|:"title 1"}, {|url|:"http://url2", |name|:"title 2"}}
  • great! is it possible get all this with {|safari|: {{|window_1|: {|url|: "http://url1", |name|: "title 1"}, {|url|:"http://url2", |name|:"title 2"}},{|window_2|: {|url|: "http://url3", |name|: "title 3"}, {|url|:"http://url4", |name|:"title 4"}}}} ? So that I could convert the record to json (e.g. with JSON Helper) and still have a safari windows structure? I wrote a script for that all to get a string-based (not record-/list-based, what I would like to have), and it is about 200 lines of code with 3 subroutines and it looks ugly even for myself
    – static
    Oct 25, 2013 at 12:21
  • If I test so: {|safari|: {|window1|: {{|url1|: "http1", |name1|: "title1"},{|url2|: "http2", |name2|: "title2"},{|url3|: "http3", |name3|: "title3"}}}} & {|safari|: {|window2|: {{|url1|: "http1", |name1|: "title1"},{|url2|: "http2", |name2|: "title2"},{|url3|: "http3", |name3|: "title3"}}}} it returns only: {safari:{window1:{{url1:"http1", name1:"title1"}, {url2:"http2", name2:"title2"}, {url3:"http3", name3:"title3"}}}} and not the merged variant, where there is a list of windows
    – static
    Oct 25, 2013 at 12:31
  • The double curly brackets (e.g. list): {|safari|: -->{{<-- |window1|: ... doesn't make any change
    – static
    Oct 25, 2013 at 12:38
  • sorry for so many off-topic comments, but I almost solved this to myself: how to set the the key of the record in the runtime? so set end of w_l to {|window & "_" & window_i :t_l} ?
    – static
    Oct 25, 2013 at 12:50

You must log in to answer this question.

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