LoginSignup
0
0

More than 5 years have passed since last update.

Finder で指定したフォルダをルートとしてローカルサーバを起動する

Posted at

Mac 限定ネタです。
要は "php -S" を Finder の「サービス」から実行するというだけですが、、

環境

Mac OS X 10.10.3
Automator バージョン 2.5 (409.2)

Automator.app の保存先をローカルに変更する

いつからか Automator.app の保存先がデフォルトで iCloud になっているので、システム環境設定 > iCloud からこれを無効にします。

iCloud Drive の「オプション...」を選択。
hoge.jpg

Automator.app のチェックを外します。
スクリーンショット 2015-08-27 15.51.24のコピー.jpg

Automator で サービス を作成

Automator.app を起動して新規 > サービスを選択します。
スクリーンショット 2015-08-27 15.43.18.png

「"サービス"は、次の選択項目を受け取る」を「フォルダ」に、「検索対象」を「Finder.app」に設定します。
スクリーンショット 2015-08-27 15.44.46.png

AppleScript を書く

アクション一覧から「AppleScript を実行」をダブルクリックして追加し、以下のスクリプトをコピペしてください。

on run {argv}
    display dialog "Enter port number" default answer "8888"
    set targetPort to text returned of result

    tell application "Terminal"
        set currentTab to do script "cd " & (argv)'s POSIX path
        delay 1
        do script "php -S localhost:" & targetPort in currentTab
    end tell
end run

保存後、Finder.app でフォルダを右クリックして「サービス」の中を覗くと保存した名前でワークフローが登録されていますので、あとは実行するだけです。
スクリーンショット 2015-08-27 16.09.46.png

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0