Xcode快捷Behavior

前言

在Xcode开发环境中,有一些可以自定义的快捷Behavior,可以大大提高开发效率。


自定义Behavior

如何配置Behavior

以下是在Xcode中配置Behavior的通用步骤:

  1. 打开Xcode的偏好设置。
  2. 点击“Behaviors”选项卡。
  3. 点击左下角的"+"号创建一个新的Behavior。
  4. 为Behavior命名,例如你希望调用的脚本名。
  5. 在“Run”下选择“Script”,然后选择你写好的脚本。
  6. 按需配置快捷键,并保存。

现在,每当你使用配置的快捷键时,它就会运行你的脚本。

Behavior示例

Behavior1:打开终端并cd到当前工作目录

创建open_terminal.sh,写入以下内容

#!/bin/bash
open -a terminal "`pwd`"

并添加执行权限

sudo chmod +x open_terminal.sh

添加Behavior并在Run处选中该脚本路径,配置好快捷键。
当你使用配置的快捷键时,就会打开终端并cd到当前工作目录

后面就只给出脚本代码了,其他步骤一样的就不重复了

Behavior2:打开项目文件夹

#!/bin/bash

# Path to your project
project_path="$1"

# Open the project folder in Finder
open "$project_path"

Behavior3:执行pod install

#!/bin/bash

current_directory=`pwd`

osascript -e "
  tell application \"iTerm\"
      activate
      if (count of windows) = 0 then
          set newWindow to (create window with default profile)
          tell newWindow
              tell current session
                  write text \"cd $current_directory; pod install\"
              end tell
          end tell
      else
          tell current window
              create tab with default profile
          end tell
          tell current session of current tab of current window
              write text \"cd $current_directory; pod install\"
          end tell
      end if
  end tell"

总结

通过配置Behavior,我们可以更快速地访问项目文件夹和命令行等,从而提高开发效率。如果大家有其他想法或者需求,欢迎在评论区留言,后续会不断更新👏🏻。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容