サーチ…


前書き

Applescriptは、ターミナルコマンドラインから直接使用して多数のタスクを実行できる強力なスクリプト言語です。

このセクションに記載されているすべての例は、ターミナルアプリケーションから使用するためのものです。

SafariまたはGoogle Chromeで現在のURLを取得する

ターミナルコマンドラインから

Safariから現在の URLを取得する

osascript -e 'tell app "safari" to get the url of the current tab of window 1'

Google Chromeで 有効な URLを取得する

osascript -e 'tell app "google chrome" to get the url of the active tab of window 1'

SafariまたはGoogle Chromeで現在のページのタイトルを取得する

Safariで Webページの名前を取得する

osascript -e 'tell app "safari" to get the name of the current tab of window 1'

Google Chromeでウェブページのタイトルを取得する

osascript -e 'tell app "google chrome" to get the title of the active tab of window 1'

シェルスクリプトとしてAppleScriptを使用する

あなたは単線Applescriptコードに限られていません。ここでは前の2つの例を取り上げ、それらを1つの関数に結合します。

#!/bin/bash    

pageinfo() {
  osascript -e \
  'tell app "safari" 
    tell the current tab of window 1
      return {url & "\n" & name}
    end tell
  end tell'
}


Modified text is an extract of the original Stack Overflow Documentation
ライセンスを受けた CC BY-SA 3.0
所属していない Stack Overflow