肝はこの辺・・・
配列の定義と要素追加
--定義
set linkArray to {}
--要素の追加
set the end of linkArray to {urlTitle:tabName, urlLink:tabURL}
アプリケーション(Safari)に指示を出す
tell application "Safari"
end tell
1つのウインドウ内にあるタブの数
-- tell application "Safari"内で・・・
set tabcount to number of tabs in window inWindowNumber
指定回数のループ
--1〜タブ数までループ、変数yがインクリメントされる
repeat with y from 1 to タブ数
end repeat
コード全体
-- ========================================
-- 戻り値:配列
-- key : urlTitle
-- key : urlLink
-- ========================================
to tellSafariToGetURLsOfWindowByWindowNumber(inWindowNumber)
set linkArray to {}
tell application "Safari"
set tabcount to number of tabs in window inWindowNumber
try
set tabcount to number of tabs in window inWindowNumber
repeat with y from 1 to tabcount
--Get Tab Name & URL
set tabName to name of tab y of window inWindowNumber
set tabURL to URL of tab y of window inWindowNumber
set the end of linkArray to {urlTitle:tabName, urlLink:tabURL}
end repeat
end try
end tell
return linkArray
end tellSafariToGetURLsOfWindowByWindowNumber
実行
tellSafariToGetURLsOfWindowByWindowNumber(1)
結果
qiitaのページをタブで2つ開いたウインドウの結果
{{urlTitle:"ホーム - Qiita", urlLink:"http://qiita.com/"}, {urlTitle:"ホーム - Qiita", urlLink:"http://qiita.com/"}}