【ツール】SafariのWindowとTabの情報を得る [AppleScript辞書はつくれるか?]
my SafariInfo(0, 0)
on SafariInfo(getID, getTab) --|Safariウインドウ情報取得|
(* Safariが起動していなければ = false *)
(* getID, getTabが一致していれば = true *)
(* getID, getTabが不一致ならば そのウインドウを最前面にする & 情報取得 *)
(* getID, getTabが0,0なら 情報取得*)
--|Safariの起動確認|
if application "Safari" is not running then
return false
end if
tell application "Safari"
--|現在の最前面のウインドウ番号を取得|
tell window 1
set currentWindow to id
set currentTab to index of (current tab)
end tell
--|引数と同じ番号なら抜け出す|
if (currentWindow is getID) and (currentTab is getTab) then return true
--|Safariのウインドウ情報を全て手に入れる(画面がちらつくのは仕様)|
set windowList to {}
repeat with tID from 1 to (count of (every window))
tell window tID
repeat with tTab from 1 to (count of (every tab))
set current tab to tab tTab
set windowList to windowList & {{windowID:id, tabId:tTab, windowName:name}}
end repeat
end tell
end repeat
--|引数のGetIDが0ならばウインドウを並びを元に戻す。違うなら引数のウインドウを探す|
if getID is 0 then
set index of window id currentWindow to 1
tell window 1
set current tab to tab currentTab
end tell
else
try
set index of window id getID to 1
tell window 1
set current tab to tab getTab
end tell
end try
end if
end tell
return windowList
end SafariInfo
結果:
{{windowID:555, tabId:1, windowName:"Apple"}, {windowID:563, tabId:1, windowName:"Minecraft"}, {windowID:563, tabId:2, windowName:"Yahoo! JAPAN"}}
コメント 0