MacのエディターCotEditor(5.1.4)で開いているPythonファイルをターミナルで実行するアップルスクリプト
CotEditorのメニュー「スクリプト」→「スクリプトフォルダを開く」
この中に「python.@r.applescript」を置けばOK
アップルスクリプト python.@r.applescript
(*
* Use Command+R to run python on the current file
*)
tell application "CotEditor"
if exists front document then
set thisfile to POSIX path of (get file of front document) as Unicode text
set thisdir to (do shell script "/usr/bin/dirname \"" & thisfile & "\"")
set thisbase to thisdir & "/" & (do shell script "/usr/bin/basename \"" & thisfile & "\" .py")
if (thisfile is not "") then
tell application "Terminal"
activate
do script with command "python " & thisfile
end tell
end if
activate
end if
end tell