OSX中的终端脚本 [英] Terminal scripting in OSX
问题描述
我以前从未创建过脚本,并且正在寻找有关为OSX 10.6编写脚本的教程.有一个终端命令可以显示所有隐藏文件.是
I've never created a script before and am looking for a tutorial on writing a script for OSX 10.6. There is a terminal command that can show all hidden files. It's
defaults write com.apple.finder AppleShowAllFiles TRUE
killall Finder
将TRUE更改为FALSE将隐藏系统文件.我想制作一个检查AppleShowAllFiles值的脚本,如果为TRUE,则写FALSE,如果为FALSE,则写TRUE.
Changing TRUE to FALSE will hide system files. I want to make a script that checks the value of AppleShowAllFiles, and if TRUE, writes FALSE, and if FALSE, writes TRUE.
这是在TextEdit中完成并保存为.sh文件吗?脚本可以是我双击运行的脚本吗,还是必须启动终端并键入命令来执行脚本?我是新手,对不起
Is this done in TextEdit and saved as a .sh file? Can a script be something I double-click that just runs, or do I have to start terminal and type a command to execute the script? I'm a newb, sorry
谢谢大家
推荐答案
使用以下内容创建文件switchhideshow.command:
make a file switchhideshow.command with the following content:
#!/bin/sh
show=`defaults read com.apple.Finder AppleShowAllFiles 2>/dev/null`
if [ "$show" == "TRUE" ]; then
defaults write com.apple.Finder AppleShowAllFiles FALSE
else # here we come, if it is FALSE or is empty (the default)
defaults write com.apple.Finder AppleShowAllFiles TRUE
fi
killall Finder
然后:chmod a+x switchhideshow.command
准备好了.不幸的是,您应该在每次运行终端时将其关闭.另外,您可能希望查看此.它描述了如何调用Shell脚本以显示Automator Actions中的隐藏文件.
Ready. Unfortunately, you should close the terminal every time you run it. Also, you might want to look at this. It describes how to call the shell script to show hidden files from Automator Actions.
这篇关于OSX中的终端脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!