viviJIE

OS X里面‘显示系统隐藏文件’默认是不开启的,如果需要显示或隐藏系统文件,需要输入命令,然后重启Finder进程。

显示Mac隐藏文件的命令:

defaults write com.apple.finder AppleShowAllFiles -bool true
隐藏Mac隐藏文件的命令:
defaults write com.apple.finder AppleShowAllFiles -bool false

有的朋友会觉得开启显示隐藏文件Finder看上去太乱了,所以查看完文件马上关闭。开启终端,输命令,重启Finder步骤太多,正好可以借助AppleScript来简化操作。

-- 设置一个窗口,选择隐藏文件的显示,隐藏和取消
display dialog "Show hidden files?" buttons {"Show", "Hidden", "Cancel"}

-- 用switch变量来捕获操作的返回结果
set switch to button returned of result

-- 用循环来响应用户的选择
if switch is "Show" then
    -- 关闭Finder程序
    tell application "Finder" to quit
    -- 设置Finder运行参数
    tell application "System Events" to do shell script "defaults write com.apple.finder AppleShowAllFiles -bool true"
    -- 加个延时
    delay 1
    -- 重新加载Finder
    tell application "Finder" to launch
    
else if switch is "Hidden" then
    tell application "Finder" to quit
    
    tell application "System Events" to do shell script "defaults write com.apple.finder AppleShowAllFiles -bool false"
    
    delay 1
    
    tell application "Finder" to launch
    
else -- switch to "Cancel" 
    -- 测试发现如果按钮的名称是“Cancel”的话,系统会自动执行Cancel操作,不需要对操作定义
    -- 如果把“Cancel”换成其他名称,就需要自己来定义操作了
end if

用/Applications/Utilities/AppleScript\ Editor.app 打开代码,另存为应用就可以运行了:

 

分类:

技术点:

相关文章:

  • 2021-11-19
  • 2021-08-09
  • 2021-12-27
  • 2021-09-06
  • 2022-01-09
  • 2021-11-19
  • 2021-11-19
  • 2022-01-07
猜你喜欢
  • 2022-12-23
  • 2021-04-10
  • 2022-12-23
  • 2021-11-20
  • 2021-08-06
  • 2022-12-23
相关资源
相似解决方案