Skip to content

Alfred show hosts and passing selected to clipboard

Notifications You must be signed in to change notification settings

yhan219/alfred_show_hosts

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 

Repository files navigation

Alfred是macOS上屡获殊荣的应用程序,可通过热键,关键字,文本扩展等功能提高效率。搜索Mac和网络,并通过自定义操作来控制Mac来提高生产力。

新建一个workflow

点击左下角+-->Templates-->Essentials-->Script Filter to Script,填写nameicon,新建完成后如下:

修改Script Filter

双击第一个图形,进入修改页面,其中

  • keyword填写关键字,如hosts
  • 参数选项选Argument Optional,即参数选填
  • language/bin/bash,with input as argv
    • with input as argv参数通过query=$1获取
    • with input as query参数通过query="{query}"获取

编写脚本

#!/bin/bash

HOSTS=""
# Handle action
if [[ "$1" != "" ]]; then
  if [[ "$1" == "Null" ]]; then
    exit
  fi
  HOSTS=`cat /etc/hosts | grep '^[^#].*' | grep $1`
else
 HOSTS=`cat /etc/hosts | grep '^[^#].*'`
fi
echo "<?xml version='1.0'?><items>"
while read -r HOST; do
  ARRAY=(${HOST// / })
  echo "<item uid='${ARRAY[0]}' arg='${ARRAY[0]}'><title>${ARRAY[1]}</title><subtitle>${ARRAY[0]}</subtitle></item>"
done <<< "$HOSTS"
echo "</items>"

alfred workflow主要是通过构建如下结构并输入:

<?xml version="1.0" encoding="utf-8"?>

<items> 
  <item uid="id" arg="参数,可传递到下一个流程" valid="yes" autocomplete="yes">
    <title>标题</title>
    <subtitle>副标题)</subtitle>
    <icon>图标,缺省显示应用图标</icon>
  </item> 
</items>

填写完成后如下:

添加粘贴

我们需要将选中的ip复制到粘贴板

  • 界面上删除第二个图形
  • 右键新建粘贴图形,右键-->Outputs-->Copy to Clipboard,弹出框直接save即可
  • 界面上从图形一拉一条线到图形二即可 完成后如下:

效果图

选中选项后,回车,IP即拷贝到粘贴板

参考文献

Help and Support > Workflows

https://blog.yhan219.com/alfred-workflow/

About

Alfred show hosts and passing selected to clipboard

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages