检查"defaults write com.apple.finder CreateDesktop"的状态



我想写一个简单的shell脚本(用于mac(,在执行时隐藏或显示桌面上的所有图标。要做到这一点,很明显:defaults write com.apple.finder CreateDesktop true/falsekillall Finder。

简而言之,我想要一个可执行文件,也许还有一个键盘组合快捷键。这就是我所拥有的:

#!/bin/bash 
echo doing stuff with icons
defaults write com.apple.finder CreateDesktop false
killall Finder
osascript -e 'tell application "Terminal" to close (every window whose name contains ".command")' &
# exit

这就是我想要的:

#!/bin/bash 
echo doing stuff with icons
#check status 
if defaults write com.apple.finder CreateDesktop == true; then 
defaults write com.apple.finder CreateDesktop false
killall Finder
else
defaults write com.apple.finder CreateDesktop true
killall Finder
fi
osascript -e 'tell application "Terminal" to close (every window whose name contains ".command")' &
exit

我今天也在尝试同样的事情,刚刚找到了你的帖子。这个vvv对我有用。我把它放在快捷方式中,并固定在菜单栏上。

if $(defaults read com.apple.finder CreateDesktop); then
defaults write com.apple.finder CreateDesktop false; 
afplay /System/Library/Sounds/Submarine.aiff
else
defaults write com.apple.finder CreateDesktop true;
afplay /System/Library/Sounds/Ping.aiff
fi; killall Finder

来源:Macmost post

最新更新