Alfred使用

设置

Alfred 启动后,点击帽子图标,选择 Preferences... 打开设置面板

General: 通用设置

  • Startup: 是否在系统启动时自启动Alfred。神器,默认勾上,不解释。
  • Alfred Hotkey: 调出Alfred操作界面的热键。默认为 Alt + 空格
  • Where are you: 你在哪个国家。Alfred内置了常用网站搜索功能,在搜索时打开对应国家的网站。

Features: 特性界面

  • Alfred几乎所有搜索功能都在这个界面设置。免费用户(没有购买Powerpack开启Workflows)重点关注的地方了。
  • Features包含的所有功能,本文不打算讲解所有的功能,只讲解最常用的。如:Default Results、File Search、Web Search、Calculator等。
  1. Default Results: 默认结果
  • Essentials: 可设置搜索“应用程序”、“联系人”、“设置”、“Safari书签”。
  • Extras: 可设置搜索“文件夹”、“文本文件”、“压缩文件”、“个人文档目录”、“图片”、“AppleScript”等其他文件。
  • Unintelligent: Search all file types 搜索所有文件类型。若勾选此项不但影响巡查速度,还混淆默认搜索结果。Alfred建议用户使用 Find+空格+文件名 来查询文件或文件夹;使用 Open+空格+文件名 也可以。
  • Search Scope: 设置Alfred查询时 会搜索的文件夹范围,可自己添加和删除。
  • Fallbacks: 若上面的查询搜索不到结果时,就会调用这里设置的网站或搜索引擎来进行进一步的查询。 默认反馈结果为 GoogleAmazonWikipedia 网页搜索。 可以自己添加搜索引擎。
  1. Web Search: 网页搜索
  • KeywordAlfred命令/关键字DisplayText 为此搜索功能的标题;Custom 有图标表示这个为用户自定义;Enabled 为是否启用。
  • Alfred网站搜索的设置,这是本人使用最频繁的功能。在图中可看到Alfred默认设置了很多搜索网站,但几乎都是国外网站,因为天朝特色,很多都是我们用不上,因此需要添加自定义的搜索设置。
    • 点击右下角的 Add Custom Search
    • 根据下面的示意图在弹出界面中输入对应信息,其中网站图标可忽略,然后保存即可。
    • 比如我自定义的百度搜索,信息如下:
      • Search URL: https://www.baidu.com/s?ie=utf-8&f=8&rsv_bp=1&ch=&tn=baiduerr&bar=&wd={query}
      • Title: baidu
      • Keyword: bd
      • Validation: 为热爱祖国,此项可随意。
      • Alfred 输入 bd+空格+查询内容, 回车即自动打开百度进行搜索。
      • 只要在对应的网站上搜索一次,记下当时的网址,并把具体的搜索内容改为 {query} 就可以找到我们自定义搜索设置中所需要的 Search URL 信息了。
  1. Calculator: 计算器
  • 直接在Alfred 输入 1+1 可以立即得到结果
  • 输入 = 来进行复杂运算,Alfred支持很多高级的数学函数。eg: =sin(1)
  1. Clipboard: 剪切板
  • 开启Alfred的剪切板功能。
  • 查看Alfred剪切板历史记录。默认热键为 Command + Alt + C
  • 清空Alfred剪切板。在Alfred操作界面中输入 clear

Advanced: 高级设置

  1. 配置同步
  • 点击 Set sync folder... 设置Alfred配置导出的目录。点击 Reveal in Finder 查看Alfred配置所在的目录。
  • 只要将Alfred配置导出的目录设置为 Dropbox 同步目录,就可以实现云同步。

Workflow: 神器啊, 这里收藏自己使用的Workflow。

Workflow List
Workflow List
Workflow packal

  • Github: 更便捷地使用Github

  • Github Search: 在Alfred上列出Github的搜索结果

    • 使用:github 要搜索的库名 eg: github YYKit
    • 对搜索结果按回车,打开Github网页。
    • 对搜索结果按Cmd + c,复制链接。
    • 按住Cmd再点击搜索结果,打开pull请求。
    • 按住Alt再点击搜索结果,打开issues页面。
  • Stackoverflow: Stackoverflow 的查询结果

    • 使用:.so 要查询的问题 eg: .so ios
  • Hash: 哈希工具,对字符串和文件进行MD5、SHA1等常用哈希,另外支持Base64等。

    • 对字符串进行SHA1:sha1 kyson
  • Copy Path: 将Finder中文件的路径复制到剪切板中。(该网址下包含众多workflow)

    • 点击 workflow -> copy path -> hotkey 修改此Workflow的热键为 Ctrl + Command + C
    • 在Finder中选中文件后执行此热键即可复制该文件的路径。
  • CodeVar: 生成可用的代码变量

    • 小驼峰命名法: xt
    • 大驼峰命名法: dt
    • 下划线命名法: xh
    • 常量命名法: cl
  • 有道词典: 有道词典 并同步到单词本

  • 改变默认终端为 iTerm

    • 首先将 Terminal 的 Application 改变为 Custom:
    • 然后在输入栏中输入:
      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      13
      14
      15
      16
      17
      18
      19
      20
      21
      22
      23
      24
      25
      26
      27
      28
      29
      30
      31
      32
      33
      34
      35
      36
      37
      38
      39
      40
      41
      42
      43
      44
      45
      46
      47
      48
      49
      50
      51
      52
      53
      54
      55
      56
      57
      on write_to_file(this_data, target_file, append_data)
      try
      set the target_file to the target_file as string
      set the open_target_file to open for access file target_file with write permission
      if append_data is false then set eof of the open_target_file to 0
      write this_data to the open_target_file starting at eof
      close access the open_target_file
      return true
      on error
      try
      close access file target_file
      end try
      return false
      end try
      end write_to_file


      on alfred_script(q)

      -- Write the command to run to a file. This is done because Applescript quoting is impossible to get right, esp. for backslashes.
      set tmp_dir to path to temporary items as string from user domain
      set applescript_alfred_file to tmp_dir & "alfredscript"
      set alfred_file to POSIX path of applescript_alfred_file
      write_to_file(q & return, applescript_alfred_file, false)

      -- Create this file, which prevents iTerm2 from restoring a saved window arrangement.
      do shell script "touch ~/Library/Application' Support/iTerm/quiet'"

      -- Test cases:
      -- 1. iTerm2 running, has windows open. Should open a new window for Alfred command.
      -- 2. iTerm2 running, no windows open. Should open a new window for Alfred command.
      -- 3. iTerm2 not running, set to restores arrangement. Should not restore arrangement but open a new window for the Afred command.
      -- 4. iTerm2 not running. No windows to restore. Should open a single window for the Alfred command.
      -- 5. iTerm2 not running. Has windows to restore. Restores windows and then opens a new window for the Alfred command.

      -- Compose a script. This is necessary because compiling in a 'tell application' command causes the app to be launched, which would happen prior to the creation of the quiet file.
      set theScript to "tell application \"iTerm2.app\"
      if (exists current window) then
      tell current window to create tab with default profile
      tell current session of current window
      write contents of file \"" & alfred_file & "\"
      end tell
      else
      create window with default profile
      tell current session of current window
      write contents of file \"" & alfred_file & "\"
      end tell
      end if
      activate
      end tell"

      -- Invoke the script.
      run script theScript

      -- Clean up
      -- do shell script "rm -f ~/Library/Application' Support/iTerm/quiet' /tmp/alfredscript"
      end alfred_script


-------------The End-------------

本文标题:Alfred使用

文章作者:kysonyangs

发布时间:2017年10月16日 - 15:10

最后更新:2020年05月17日 - 16:05

原始链接:https://kysonyangs.github.io/default/Alfred使用/

许可协议: 署名-非商业性使用-禁止演绎 4.0 国际 转载请保留原文链接及作者。