zoukankan      html  css  js  c++  java
  • Mac下使用Automator实现隐藏和显示

    本文使用Makdown编辑


    通常系统中打开一个文件有好多种方法,编辑也是。例如你要打开OmniGraffle来画个图(suppose you are working on the Mac OS X)
    1.可以使用命令open来启动应用:open -a OmniGraffle [FiletoEdit]
    2.各种文件管理器,默认的Finder, 还有PathFinder, DCommander, Transmit等,只要能调用Finder的open,save的也可以,Dock;
    3.当然AppleScript/JavaScript, Shell(bash,zsh)也可以;
    4.Alfred, Spotlight这类搜索类的;

    Access Hidden Files or Folders

    但是,有些文件和文件夹是隐藏的,Finder考虑到这个提供了『⌘+⇧+G』,这样只要你输入正确的路径就可以在finder中显示,这样可以通过点击继续任务,常用的~/Library$HOME/下的其他隐藏的文件夹都可以访问了
    还有,通过 defaults write ... 来配置来显示:
    defaults write com.apple.finder AppleShowAllFiles -bool true来显示所以隐藏的
    defaults write com.apple.finder AppleShowAllFiles -bool false了关闭
    还可以直接修改文件和文件夹的flag来弄:
    chflags nohidden ***FileorFoldertoOperate***

    But, 每次都有敲入这么多字符太麻烦,所以立马会想到用Shell的alias

    alias showAll='defaults write com.apple.finder AppleShowAllFiles -bool true'
    alias hideAll='defaults write com.apple.finder AppleShowAllFiles -bool false'

    添加到.bash_profile, source .bash_profile,刷新Finder之后
    But, 每次都有打开Terminal,尤其配置多了之后启动起来超级慢

    更换iTerm 2

    But, 这个配置是全局的,很多时候我只需要显示某一个或几个文件和文件夹,所以想到chflags

    chflags nohidden Afile
    chflags nohidden BFolder
    chflags nohidden CFolder
    ...
    ...
    # after
    chflags hidden Afile
    chflags hidden BFolder
    chflags hidden CFolder
    ...
    

    OK啦,但是很多时候打开Terminal,ls -la, ls -l, open, vim,发现并不需要显示或者隐藏什么
    而打开Finder吧,有时候又需要显示隐藏

    Object
    所以想到Mac自带的任务流程工具 AppleScript/Automator,
    写个Service添加到Folder

    1. 选中文件夹
    2. 可以选择『隐藏该文件夹』「Hide This」『显示该文件夹下所有隐藏的文件(夹)』「Show All Under」
    3. 允许选择多个文件夹
    4. 可以隐藏文件
      Services works with Finder

    Add a Finder Service


    下面实现一下常用的几个


    1. 右键任何一个文件夹,选择Services->Create Service
    2. 搜selected,拖Get Selected Finder Items到右边panel
      step2
    3. 搜shell,拖Run Shell Script到右边panel
    4. Shell选/bin/bash,Pass Input选 as arguments
      4.1 隐藏 「hide」
    for item in $@;do
     # doesn't matter it is a file or a directory
     echo $item
     chflags hidden "$item"
    done
    

    4.2 显示文件夹下的所以隐藏项「unhide under」

    for folder in $@;do
        echo $folder
        if test -d $folder;then
    	for dir in $folder/*;do
    	    if test -d $dir;then
    		chflags nohidden "$dir"
    		cat "$dir
    " >> .aHiddenItems
    	    fi
    	done
        fi
    done
    

    4.3 隐藏文件夹下之前隐藏的「hide under」

    for folder in $@;do
        if test -d $folder;then
            echo $folder
            if [ -d $folder/.aHiddenItems ];then
                for item in `cat $folder/.aHiddenItems`;do
                    chflags hidden "$item"
                done
            fi
        fi
    done
    
    1. Step和Run测试没有错误
      5.『⌘+S』保存,会自动保存到~/Library/Services/下
    2. 现在可以用了
    天和地是灰色的,砖和瓦也是灰色的。临街的墙几经风化,几经修补,刷过黑灰、白灰,涂过红漆,书写过不同内容的标语,又终于被覆盖;风雨再把覆盖层胡乱地揭下来,形成一片斑驳的杂色,融汇于灰色的笼罩之中。路旁的树木苍黑,瓦楞中芳草青青。 远处,炊烟缭绕。迷蒙的曙色中,矗立着...
  • 相关阅读:
    TypeError: translate() takes exactly one argument (2 given)
    matlab为long term visual tracking数据集生成groundtruth.txt
    Linux下为python3安装opencv
    tensorflow全连接层降维
    MDNet结果json文件转成long term visual tracking (oxuva)评估所需的csv文件的python脚本
    no module named caffe
    IIS短文件/文件夹泄露漏洞
    点击劫持漏洞
    WPF Combobox数据绑定 Binding
    关于Win10安装vs2013简体中文语言包无法安装的问题
  • 原文地址:https://www.cnblogs.com/raybiolee/p/5289342.html
Copyright © 2011-2022 走看看