Alfred is a powerful way to make your Mac more efficient. With Alfred you can basically do anything without a mouse. Compared to the Mac’s own focused search, it can be called a crushing advantage.
Below is the Alfred icon. The website is www.alfredapp.com/
Before introducing its use, let’s take a look at its basic functions.
Basic Functions
First use the shortcut Alt + space to open the Alfred interface.
Alfred’s common base functions include querying documents, specifying web site search, clipboard history, integrating iTerm2, computer dictionary translation, integrating 1Password, system functionality, zooming in on content, and more. I’m going to pick a few of them to show you briefly.
Query the document
You can use the following four shortcuts to query documents: \
- Open: Opens a file
- Find: Opens the document directory
- In: Searches the file
- Tags: Specifies the file label
The following figure shows an example of the find command.
Specify the site to search for
Alfred can specify search engine keywords to simplify the search.
Taking user-defined Baidu as an example, if we want to make BD as the keyword of Baidu search engine, we can perform the following configuration:
After the configuration is complete, you can use the BD keyword to specify Baidu as a search engine.
Clipboard history
You can set how long the file should be saved, activate the clipboard shortcut, or use Clipboard to activate and clear the clipboard.
Integrated iTerm2
Alfred also owns iTerm2, the Mac’s most useful command-line tool.
We can set custom commands to it, for example:
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_scriptCopy the code
Enter ls -al and press Enter to automatically execute the command in iTerm2.
Use workflow
Once you understand the basic functionality, it’s back to Alfred’s workflow, which provides interface documentation for users to invoke. \
Interface documentation: www.deanishe.net/alfred-work…
Here’s an example of Alfred’s workflow by using the code command to open the project folder by selecting pycharm or vscode according to the project directory.
First add a new workflow, specifying Name as code.
Then set the project directory public variable.
Right-click to add a script filter script.
To add a script file, right-click Open in Finder to Open the Workflow directory and download the latest version of Alfred-Workflow from GitHub (github.com/deanishe/al… The Workflow directory is copied to the open workflow directory.
Create a new index.py file with the following code:
import sys import os from os import listdir from os.path import isdir, join, expanduser from workflow import Workflow3, 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): Args [0] log.debug('searchKey: '+ searchKey) # fileList = wf.cached_data('projects', getFileList, 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), Alfred wf.send_feedback() if __name__ == '__main__': wf = Workflow3() log = wf.logger sys.exit(wf.run(main))Copy the code
Go back to the Alfred workflow and add the pass parameter variable.
Added list selection, added user selection list.
Add conditional judgment to identify which software the user has selected.
Then add two branch Open File operations and Open the File using the corresponding program.
Finally, open the Alfred popup and type code + project directory to start your Alfred journey.
Recommended reading
## Golang Options for common design patterns
How does the final boss hide himself in ## Inversion?