AppleScript 関数を作成する

AppleScript 関数を作成する

AppleScriptで、関数を作成する手順を記述してます。

環境

  • ProductName: macOS
  • ProductVersion: 11.6
  • BuildVersion: 20G165

関数を作成

関数は、以下の構文で使用可能です。

on 関数名(引数)
	処理
end f

関数名(引数) 

実際に、以下のコードで「test.scpt」というファイル名で作成して、for文を使用してみます。

on f(x,y)
	x + y
end f

f(1,2) 

実行してみます。

osascript test.scpt

実行結果

関数が使用されていることが確認できます。

on f given hoge:x, foo:y
	x - y
end f

f given foo:5, hoge:7

引数に名前をつけることも可能です。

on f given hoge:x, foo:y
	x - y
end f

f given foo:5, hoge:7

実行結果