有没有办法用终端脚本打开/关闭隐藏文件的可见性?
伪代码如下:
是否可以查看隐藏文件
设置 com.apple.Finder AppleShowAllFiles false
别的
设置 com.apple.Finder AppleShowAllFiles true
killall 查找器
答案1
#!/bin/bash
k="com.apple.Finder AppleShowAllFiles"
b=$(defaults read $k 2>&1 /dev/null)
[[ "$b" == 1 ]] && b=false || b=true
defaults write $k -bool $b
osascript -e 'tell app "Finder"
quit
delay 0.2
launch
activate
end'
或者 AppleScript 版本:
set k to "com.apple.finder AppleShowAllFiles"
set r to do shell script "defaults read " & k
do shell script "defaults write " & k & " -bool " & (r is 0 as text)
tell application "Finder"
quit
delay 0.2
launch
delay 0.2
activate
end tell