共计 2617 个字符,预计需要花费 7 分钟才能阅读完成。
Alfred 是一款性能十分弱小,能无效晋升 Mac 电脑应用效率的神器。能够说有了 Alfred 你就基本上能够脱离鼠标实现各种操作。相比 Mac 自带的聚焦搜寻,齐全能够称得上领有碾压性的劣势。
下图是 Alfred 图标,官网为:https://www.alfredapp.com/
在介绍它的应用前,咱们先来理解一下它的基本功能。
基本功能介绍
首先应用快捷键 Alt + 空格 关上 Alfred 操作界面。
Alfred 的罕用根底性能为查问文档、指定网站搜寻、剪切板历史、集成 iTerm2、计算机字典翻译、集成 1password、零碎性能、放大显示内容等等 。 接下来筛选其中几个为大家做简略展现。
查问文档
能够通过以下四种快捷方式进行文档查问操作:\
- open: 关上文件
- find: 打开文档目录
- in: 在文件中搜寻
- tags: 指定文件标签
下图是 find 命令的应用示例。
指定网站进行搜寻
Alfred 能够指定搜索引擎关键词,简化搜寻形式。
以自定义百度为搜索引擎为例,如果咱们要让 bd 作为百度搜索引擎的关键词,那咱们能够进行如下配置:
实现配置后就能够应用 bd 关键字指定百度作为搜索引擎了。
剪贴板历史
咱们能够设置文件保留的时长、激活剪切板的快捷键、或者间接应用 clipboard 激活、应用 clear 革除剪切板。
集成 iTerm2
作为 Mac 最好用的命令行工具 iTerm2,Alfred 也是领有的。
咱们能够对它设置自定义命令,例如:
on alfred_script(q) | |
if application "iTerm2" is running or application "iTerm" is running then | |
run script " | |
on run {q} | |
tell application \"iTerm\" | |
activate | |
try | |
select first window | |
set onlywindow to true | |
on error | |
create window with default profile | |
select first window | |
set onlywindow to true | |
end try | |
tell the first window | |
if onlywindow is false then | |
create tab with default profile | |
end if | |
tell current session to write text q | |
end tell | |
end tell | |
end run | |
" with parameters {q} | |
else | |
run script " | |
on run {q} | |
tell application \"iTerm\" | |
activate | |
try | |
select first window | |
on error | |
create window with default profile | |
select first window | |
end try | |
tell the first window | |
tell current session to write text q | |
end tell | |
end tell | |
end run | |
" with parameters {q} | |
end if | |
end alfred_script |
输出 ls -al 回车会将命令主动在 iTerm2 中执行。
应用工作流程
理解基本功能后,重点还是回归到 Alfred 的工作流程,官网提供了接口文档不便用户进行调用。\
接口文档:https://www.deanishe.net/alfr…
上图是 Alfred 的工作流程示意图,咱们通过应用 code 命令依据我的项目目录抉择 pycharm 或 vscode 关上我的项目文件夹,这一例子来看一下 Alfred 的工作流程。
首先新增一个工作流,指定 Name 为 code。
而后设置我的项目目录公共变量。
右键新增一个 script filter 脚本。
如果须要新增脚本文件,能够右键点击 Open in Finder 关上该工作流所在目录,从 GitHub 下载最新版本的 Alfred-Workflow(https://github.com/deanishe/a…),解压并将其中的 workflow 目录复制到关上的这个工作流目录中。
新建 index.py 文件,代码如下:
import sys | |
import os | |
from os import listdir | |
from os.path import isdir, join, expanduser | |
from workflow import Workflow3, web, ICON_WEB | |
# 获取文件列表 | |
def getFileList(): | |
args_list = wf.args | |
result = [] | |
for path in args_list[1:]: | |
# path = wf.args[1] | |
log.debug('path:' + path) | |
path = expanduser(path) | |
result.extend([{"file": f, "path": path} for f in listdir(path) if isdir(join(path, f))]) | |
return result | |
def main(wf): | |
# 获取搜寻参数 | |
searchKey = wf.args[0] | |
log.debug('searchKey:' + searchKey) | |
# 文件列表缓存 3s | |
fileList = wf.cached_data('projects', getFileList, max_age=3) | |
# 依据 query 过滤目录 | |
for item in fileList: | |
if (searchKey and (searchKey in item.get('file'))): | |
title = item.get('file') | |
wf.add_item(title=title, subtitle=item.get('path'), arg=os.path.join(item.get('path'), title), valid=True) | |
# 把应该展现的内容发送给 Alfred | |
wf.send_feedback() | |
if __name__ == '__main__': | |
wf = Workflow3() | |
log = wf.logger | |
sys.exit(wf.run(main)) |
回到 Alfred 工作流,增加传递参数变量。
新增列表抉择,增加用户抉择列表。
增加条件判断,分别用户抉择的软件是哪一个。
而后新增两个分支 Open File 操作,并应用相应程序关上文件。
最初在实现全副设置后关上 Alfred 弹框,输出 code + 我的项目目录,开始你的 Alfred 应用之旅吧。
举荐浏览
## Golang 常见设计模式之选项模式
##《逆局》最终 boss 暗藏本人的形式是?