[Automator & AppleScript] Automator: OpenInTerminal を修正
空白を含むパスを正常に開けない問題を修正しました。
[markdown]
> * [DriftwoodJP/automator-workflows](https://github.com/DriftwoodJP/automator-workflows)
> * [Automator: Finder で開いているディレクトリを Terminal.app で開く | deadwood](https://www.d-wood.com/blog/2013/12/27_5162.html)
## 今回の修正で学んだ点
### Finder で開いているウィンドウのパスを取得する
`insertion location as alias`
> * [MacOSX – Finderで開いているウィンドウのパスをシェルスクリプトで取得する – Qiita](http://qiita.com/mattintosh4/items/7b4918b70ee266216fcc#comment-8ea353e922ebb040b0c6)
“`prettyprinted
/usr/bin/osascript -e ‘tell application “Finder” to get POSIX path of (insertion location as alias)’
“`
他の手法であったバグも回避できるよう。
> * [osx – Creating an automator service to create a new document in the current directory – Stack Overflow](http://stackoverflow.com/questions/12183967/creating-an-automator-service-to-create-a-new-document-in-the-current-directory)
### 値を quote で囲む
`quoted form of` を使うと、`’` で囲まれる。
“`applescript
tell application “Terminal”
activate
do script “cd ~” & quoted form of “/Pictures/iPhoto Library”
end tell
“`
> * [How to change directory with spaces in applescript terminal? – Stack Overflow](http://stackoverflow.com/questions/14005362/how-to-change-directory-with-spaces-in-applescript-terminal)
## ソース
AppleScript に全ての処理をまとめ、空白のパスをクォートで囲み cd できるよう修正しました。
“`applescript
on run {input}
tell application “Finder”
activate
set pwdAlias to get POSIX path of (insertion location as alias)
end tell
tell application “Terminal”
activate
do script “cd ” & quoted form of pwdAlias
end tell
end run
“`
[/markdown]