【macOS】Alfred 效率

Posted by 西维蜀黍 on 2021-05-08, Last Modified on 2021-12-31

快捷键

Workflow

Kill Process

Usage

  1. Type kill into Alfred followed by a space.
  2. Begin typing the name of the process you want to kill.
  3. When you see the process you want to kill, select it from the list as usual.
  4. Press return to kill the selected process. Alternatively, press cmd+return to kill all processes with the same name as the selected one.

IP Address

Getting your local and external IP addresses.

Usage

  1. Use the keyword ip to trigger the workflow
  2. Select IP you would like to copy or paste (local IPv4, external IPv4, local IPv6, external IPv6)
  3. Press enter to copy to clipboard and paste into the forefront application or just ⌘ + c to copy to clipboard

Epoch Converter

快速打开淘宝、GitHub

淘宝智能搜索匹配

  • 触发 key : tb

Github 智能搜索匹配

  • 触发 Key : gh

文件搜索

进行文件搜索时,还可以使用find、open和in三个关键字来操作,find是打开文件所在的文件夹,open是直接打开文件(默认就是open,不敲入关键字,即搜索文件名后回车,就是直接打开该文件)。

也可以利用Space键代替“open”关键字,按下“Space + 文件名字符串”进行搜索,更加方便快捷;

输入 find 或 open 命令,以及待搜索的文件或目录名,列出磁盘中的相关文件,可以快速定位 finder,相当于一个简易的 EasyFind。

文本内容搜索

“in”:输入“in + 文件内容字符串”,可以基于文本的具体内容进行搜索,搜索出的结果文件的内容中都包含指定的字符串。

Web Serach

  • Gmail: 打开 Gmail
  • Youtube: 在youtube 中搜索
  • Wikipedia

Clipboard

如此一来,拷贝多段内容就变得非常容易,借助 alfred,可以在一处连续拷贝,然后另一处连续粘贴,避免了频繁切换应用带来的操作疲劳;同时之前复制过的文本或图片,也不用担心过会找不到。

系统常用命令快捷操作

通过 alfred 可以快捷地操作系统锁屏、关机、重启、休眠等十几种指令,非常便捷。对于强迫症用户来说,唤起屏保、休眠、清空垃圾篓、退出应用等指令可能较为常用。

直接唤起指定终端并执行命令

通过 alfred 可以直接唤起终端窗口,并执行命令,如下所示。

以上,Application 若选择『Custom』选项,下方再贴如下一段 applescript 代码,便可以直接在 iTerm 中执行命令。

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

Ref

Reference