Macos中Automator自动操作实现文本加解密、Json格式化、字数统计等操作

文章目录

      • 一、说明
        • 打开Automator
        • 效果
      • 二、文本加密
      • 三、文本解密
      • 四、Json格式化
      • 五、字数统计

一、说明

在 Automator 的工作流程中,动作是按照从上到下的顺序执行的,每一个动作的输出默认会成为下一个动作的输入。

打开Automator

Command + 空格 : 搜索Automator

效果

Macos中Automator自动操作实现文本加解密、Json格式化、字数统计等操作_第1张图片

二、文本加密

自动操作-新建文稿-快速操作-资源库-实用工具-运行shell脚本

1.将运行Shell脚本拖入右侧的工作流。

2.勾选用输出内容替换所选文本

3.运行shell脚本中输入:

openssl aes-256-cbc -a -salt -pass pass:123456

Macos中Automator自动操作实现文本加解密、Json格式化、字数统计等操作_第2张图片

三、文本解密

自动操作-新建文稿-快速操作-资源库-实用工具-运行shell脚本

1.将运行Shell脚本拖入右侧的工作流。

2.勾选用输出内容替换所选文本

3.运行shell脚本中输入:

openssl aes-256-cbc -a -d -salt -pass pass:123456

Macos中Automator自动操作实现文本加解密、Json格式化、字数统计等操作_第3张图片

四、Json格式化

自动操作-新建文稿-快速操作-资源库-实用工具-运行shell脚本

1.将运行Shell脚本拖入右侧的工作流。

2.运行shell脚本中输入:

# Shell:/bin/bash
sed 's/\\\"/\"/g' | /usr/local/bin/jq

# Shell:/bin/zsh
/usr/local/bin/jq .

3.左侧搜剪贴板,将 拷贝至剪贴板 拖到 运行Shell脚本 模块下方。

Macos中Automator自动操作实现文本加解密、Json格式化、字数统计等操作_第4张图片

效果:

{\"recordId\":\"153040\"}

{
    "recordId":"153040"
}
#####################################
echo "{\"recordId\":\"153040\"}" | jq .
{
  "recordId": "153040"
}

问题:

操作“运行Shell脚本”遇到了错误:zsh:1: no such file or directory: /usr/local/bin/jq

解决:

brew install jq

五、字数统计

自动操作-新建文稿-快速操作-资源库-实用工具-运行shell脚本

  • 1.将运行Shell脚本拖入右侧的工作流。

  • 2.在 Shell 下拉菜单中选择 “/usr/bin/python3”。

  • 3.运行shell脚本中输入:

    import sys
    
    def count_chars(text):
        stripped_text = text.strip()
        return len(stripped_text)
    
    if __name__ == "__main__":
        print(count_chars(sys.stdin.read()))
    
  • 4.将设置变量的值 拖入右侧的工作流。

    新建一个变量,变量名WordCount,值不用填。

  • 5.将显示通知 拖入右侧的工作流。

    设置标题:统计字数

    设置副标题:WordCount

Macos中Automator自动操作实现文本加解密、Json格式化、字数统计等操作_第5张图片

你可能感兴趣的:(Mac,macos,Automator,自动操作,Json格式化,统计字数)