2
2

More than 3 years have passed since last update.

Xcodeでショートカットを自作し 煩雑な pod install 作業をなくそう

Last updated at Posted at 2020-09-26

はじめに

業務で同時に複数のプロジェクトを見ることがあり、平均すると1日1回ぐらいterminalを開いてpod-installのコマンドを叩いています。本記事はiOSアプリ開発者が良く使うCocoaPodsのコマンドpod-installの作業を楽にするtipsです。XcodeにはBehaviorsと言う機能があり、様々な動作やイベントを設定・追加できます。 その機能を利用して、自動でterminalを開き所定のdirectoryに移動してpod-installコマンドを叩いてくれるショートカットキーを作成します。

開発環境

Xcode12 (Xcode11でも動くと思いますが未検証)
Cocoapods

セットアップ

1. Scriptを用意

Script をダウンロード

#!/bin/sh
osascript <<END
tell application "Terminal"
if not (exists window 1) then reopen
activate
do script "cd `pwd`; pod install" in window 1
end tell
END

2. 実行権限の付与

権限の確認

$ ls -l Pod-Install.sh 
-rw-rw-r--@ 1 yasuradodo  staff  158 Sep 19 19:40 Pod-Install.sh

もし実行権限がなければ、実行権限xの付与

$ chmod u+x Pod-Install.sh  

再度権限の確認

$ ls -l Pod-Install.sh 
-rwxrw-r--@ 1 yasuradodo  staff  158 Sep 19 19:40 Pod-Install.sh

3. XcodeのBehaviorsでCustom commandを作成

XcodeのPreferencesからBehaviorsを選択し、左下にある+をタップしてCustom commandを作成します。
ショートカットには好きなキーを登録しましょう。筆者は shift + command + pにしました。
Screen_Shot_2020-09-26_at_18_30_48.png
これで、Xcode上で登録したショートカットでいつでも自動的にpod-installが実行できます。

終わりに

今回はpod-installだけでしたが、Carthage, SourceTree, SwiftLintなど様々な物に対応でき作業効率を向上できます。
他にも便利なBehaviorsの使い方などあれば、教えていただきたいです :pray:

参考文献

https://medium.com/@abhishekbedi/never-type-pod-install-again-ever-eb55386eef59
https://github.com/JeaSungLEE/Awesome-Xcode-Behaviors

2
2
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
2
2