1874
1874
FE Engineer
桌游布道者
有粤语歌就不会有世界末日

程序员必备——Mac效率工具Alfred Workflows配置

1874 - 2022-04-19 - 技术分享 / Alfred / 效率工具
2022-4-19|最后更新: 2023-4-10|
type
Post
status
Published
date
Apr 19, 2022
slug
rm057k
summary
Alfred YYDS
category
技术分享
tags
Alfred
效率工具
创建时间
Apr 7, 2023 07:15 PM
更新时间
Apr 10, 2023 05:04 AM
password
icon
Task List

引言

最近发现Alfred简直不要太好用,快速打开网址功能(Web Search)在工作中使用起来行云流水,再也不用去一堆标签中寻找常用的网址。
notion image
但是在项目开发过程中,经常需要打开或运行各种项目,所以需要经常使iTerm或者IDE进入到各种项目文件夹中。在VSCode中,大家经常会使用code命令打开项目,再配合环境变量的别名设置,使用起来很方便。但是!我是忠诚的WebStorm党派,每次打开项目都得先打开应用然后找到需要打开的项目(不过后来发现,WebStorm其实也有命令行启动器,效果也一样)。但是这么做也有一个痛点,就是需要事先配置环境变量的别名才能做到快速打开。 最近一琢磨,可以利用AflfedWorkflows功能去尝试一下,于是真被我搞出来了,这里记录一下。

开始

Open in WebStorm

WebStrom打开项目。通过code命令打开指定目录下的文件夹,快速打开项目。效果如下:
notion image

运行流程

notion image

设置

  1. 右下角新建一个Blank Workflow,配置如下:
注意Bundle id必须是唯一的才行。
notion image
  1. 右键新增一个File Filter,配置如下:
notion image
Basic Setup基础设置。
  • Keyword: code
  • with space: true
  • Placeholder Title: Open in WebStorm
  • Placeholder Subtext: 请继续输入以打开项目
  • File Types: 文件类型,随便拖一个文件夹进去表示只识别文件夹,过滤掉文件
notion image
Scope搜索范围
  • Search Scope: 指定搜索范围,将目录拖拽进去即可
notion image
FieldsLimit and Sort保持不变,可以根据自己的习惯修改
  1. 左键单击并选择添加Actions-Run Script,配置如下:
notion image
  • Language: /bin/zsh 终端,也可以选择/bin/bash 终端
  • with input as {query}: true
  • running instances: Sequentially
  • Script: /usr/local/bin/wstorm “{query}”
notion image
注意:使用/usr/local/bin/wstorm命令需要在WebStorm中开启工具-创建命令行启动器,配置脚本位置为/usr/local/bin,并配置脚本命令为wstorm
notion image

Open in iTerm

iTerm中打开文件夹。通过cd命令进入指定目录下的文件夹,快速打开项目并运行。效果如下:
notion image

运行流程

notion image

设置

  1. 新建一个Blank workflow,配置如下:
notion image
  1. 新增File Filter,配置如下:
notion image
  1. 左键单击并选择添加 Actions-Run NSAppleScript,配置如下:
notion image
-- For the latest version: -- https://github.com/vitorgalvao/custom-alfred-iterm-scripts -- Set this property to true to always open in a new window property open_in_new_window : false -- Set this property to false to reuse current tab property open_in_new_tab : true -- Handlers on new_window() tell application "iTerm" to create window with default profile end new_window on new_tab() tell application "iTerm" to tell the first window to create tab with default profile end new_tab on call_forward() tell application "iTerm" to activate end call_forward on is_running() application "iTerm" is running end is_running on has_windows() if not is_running() then return false if windows of application "iTerm" is {} then return false true end has_windows on send_text(custom_text) tell application "iTerm" to tell the first window to tell current session to write text custom_text end send_text -- Main on alfred_script(query) if has_windows() then if open_in_new_window then new_window() else if open_in_new_tab then new_tab() else -- Reuse current tab end if else -- If iTerm is not running and we tell it to create a new window, we get two -- One from opening the application, and the other from the command if is_running() then new_window() else call_forward() end if end if -- Make sure a window exists before we continue, or the write may fail repeat until has_windows() delay 0.01 end repeat send_text(query) call_forward() end alfred_script

大功告成!

MacOS开发环境治理-卸载nvm/node并重新安装第六章 状态更新