AppleScriptでsimpleHTTPServerの開始と停止をtoggleする
Finderで最前面のウインドウ(なければDesktop)を配信します。
クリップボードに"http://local〜" をコピーするので、対応バージョンのOSが揃っていればiPhoneですぐに見られます。
Photoshop CC(2018)でデバイスプレビュー機能が削除されたため作成。
terminal-notifierを使っていますが、無ければdisplay alertに置き換えて。
(terminal-notifierはbrewで)
tell application "Finder"
set myScript to "python -m SimpleHTTPServer 8888" as Unicode text
set pid to (do shell script "ps ax | grep " & (quoted form of myScript & "$") & " | grep -v grep | awk '{print $1}'")
if pid is "" then
set myDir to POSIX path of (insertion location as alias)
do shell script "(cd " & myDir & " && " & myScript & ") &>/dev/null &"
set the clipboard to "http://" & IPv4 address of (get system info) & ":8888/"
do shell script "/usr/local/bin/terminal-notifier -title 'PythonWEBサーバ' -message '" & myDir & "でWEBサーバを開始しました。アドレスをクリップボードにコピーしました。'"
else
do shell script "kill " & pid
do shell script "/usr/local/bin/terminal-notifier -title 'PythonWEBサーバ' -message 'WEBサーバを停止しました。'"
end if
end tell