zoukankan      html  css  js  c++  java
  • Mac automator bash 自动操作 右键菜单unrar解压 拷贝文件路径到剪贴板 快速删除(rm -rf) 快捷键设置

    https://tecadmin.net/pass-command-line-arguments-in-shell-script/
    https://tecadmin.net/tutorial/bash-scripting/bash-command-arguments/
    https://www.quora.com/Where-do-I-find-the-trash-sound-the-sound-when-you-empty-the-trash-in-Mac

    默认当前路径是 ~
    传递输入设置为 作为自变量

    unrar 解压:

    export LC_ALL=en_US.UTF-8
    export LANG=en_US.UTF-8
    
    for i in "$@"
    do
      f=$i
      path=$(dirname "$i")
      /usr/local/bin/unrar x "$f" "$path"
    done
    

    复制文件路径:

    # 这两句设置编码格式为 utf8,不然 pbcopy 复制中文路径时有问题
    export LC_ALL=en_US.UTF-8
    export LANG=en_US.UTF-8
    
    for f in "$@"
    do
            echo "$f" | tr -d '
    ' | pbcopy
    done
    

    快速删除:

    export LC_ALL=en_US.UTF-8
    export LANG=en_US.UTF-8
    
    # 给个弹框提示
    x=`osascript -e '
    on run argv
        set strTitle to "ARE YOU SURE"
        set strContent to "rm -rf
    " & convertListToString(argv, "
    ") & " ?"
        set btns to {"NO", "YES"}
        display dialog strContent with title strTitle buttons btns default button 2 cancel button 1 with icon caution
        get the button returned of the result
    end
    
    on convertListToString(theList, theDelimiter)
        set saveTID to text item delimiters
        set text item delimiters to theDelimiter
        set theString to theList as text
        set text item delimiters to saveTID
    
        return theString
    end convertListToString
    ' $@`
    
    if [[ $x = "YES" ]]; then
        for f in "$@"
        do
            rm -rf "$f"
        done
        afplay /System/Library/Components/CoreAudio.component/Contents/SharedSupport/SystemSounds/finder/empty trash.aif
    fi
    

    最后设置快捷键:

    automator 的 bash 环境:
    参考链接

    Anything run from the Finder or elsewhere in the Aqua user interface knows nothing about your command line environment. There are some hacks you can do, but it is better to make your script stand-alone. If you need a particular environment, write a wrapper around it that sets up said environment and call that wrapper.

    查看所有的环境变量:export -p

  • 相关阅读:
    python基础-运算符和编码
    python介绍
    墨菲定律
    羊皮卷
    循环神经网络层
    ResNet实战
    ResNet实战
    ResNet,DenseNet
    经典卷积网络VGG,GoodLeNet,Inception
    CIFAR100与VGG13实战
  • 原文地址:https://www.cnblogs.com/hangj/p/11970820.html
Copyright © 2011-2022 走看看