SSブログ

【ツール】SafariのWindowとTabの情報を得る [AppleScript辞書はつくれるか?]

Safariで表示しているウインドウの情報(Index/Tab/タイトル)を取得する。
引数が0,0以外なら、そのウインドウを最前面にすることを試みる。

そんなスクリプトを作ってみた


my SafariInfo(0, 0)

 

on SafariInfo(getID, getTab) --|Safariウインドウ情報取得|

(* Safariが起動していなければ = false *)

(* getID, getTabが一致していれば = true *)

(* getID, getTabが不一致ならば そのウインドウを最前面にする 情報取得 *)

(* getID, getTab0,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

--|引数のGetID0ならばウインドウを並びを元に戻す。違うなら引数のウインドウを探す|

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"}}


こんなかんじですね。


nice!(0)  コメント(0)  トラックバック(0) 
共通テーマ:パソコン・インターネット

nice! 0

コメント 0

コメントを書く

お名前:
URL:
コメント:
画像認証:
下の画像に表示されている文字を入力してください。

トラックバック 0

この広告は前回の更新から一定期間経過したブログに表示されています。更新すると自動で解除されます。