2014年1月7日火曜日

Apple Script webページを開いて閉じる

昨日に引き続き.
今度は,webページを開いて,5秒後に閉じるやつを作った.
ちなみに,ブラウザはSafari.
openでwebページを開いたら,今開いてるsafariのページに新規タブで開かれる.
普通にcloseでやってしまうと,他のも全部消えちゃうから注意.
「1's current tab」ってのが重要.
これで,タブだけ消せる.
scriptって便利だねー.


property target_URL : "http://www.google.co.jp"
set accessURL to "http://www.google.co.jp"

repeat
  display dialog "Do you want access to " & accessURL & " ?" buttons {"access", "cancel"} default button 2
  copy the result as list to {button_pressed}
  if the button_pressed is "cancel" then exit repeat
  if the button_pressed is "access" then exit repeat
end repeat

if the button_pressed is "access" then
  tell application "Safari" --Safariにコール
    open location target_URL --target_URLにアクセス
    set theID to window 1's current tab --theIDwindow 1's current tabを代入
    delay 5 --5秒待つ
    close theID --theIDを閉じる(開いたタブを閉じる)
    --close window 1's current tab
  end tell
end if


2014年1月6日月曜日

Apple Script 指定したweb pageにアクセス

新年あけましておめでとう御座います.
今年もよろしくお願い致します.

さて,Apple script なるものを使って特定のweb siteにアクセス出来るスクリプトを書きました.ちなみに,意味はありません.
簡単な事なんでしょうが,初心者の僕にとっては・・・
いろんなサイト見て,やっと出来ました.
以下,作ったやつです.

property target_URL : "http://www.google.co.jp"
set accessURL to "http://www.google.co.jp"

repeatdisplay dialog "Do you want to access " & accessURL & " ?" buttons {"access", "cancel"}

  default button 2copy the result as list to {button_pressed}
  if the button_pressed is "cancel" then exit repeat
  if the button_pressed is "access" then exit repeat
end repeat


if the button_pressed is "access" then
  delay 5 --second wait
  open location target_URL
end if


すごく単純です.
まず,ダイアログ表示して,"access"を選べば,5秒後にgoogleのページへ飛びます.
"cancel"を押せば,ダイアログが消えて終わりです.

これにどれだけの時間を費やしたか・・・
でも,出来たから,よかったです.ほんと.

なんか,これで終わってしまいそうな予感がしますが,まあ良いや.