简体   繁体   English

OSX中的终端脚本

[英]Terminal scripting in OSX

I've never created a script before and am looking for a tutorial on writing a script for OSX 10.6. 我以前从未创建过脚本,正在寻找编写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

Changing TRUE to FALSE will hide system files. 将TRUE更改为FALSE将隐藏系统文件。 I want to make a script that checks the value of AppleShowAllFiles, and if TRUE, writes FALSE, and if FALSE, writes TRUE. 我想创建一个检查AppleShowAllFiles值的脚本,如果为TRUE,则写入FALSE,如果为FALSE,则写入TRUE。

Is this done in TextEdit and saved as a .sh file? 这是在TextEdit中完成并保存为.sh文件吗? 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 我是个新手,抱歉

Thanks guys 多谢你们

You can use the .command extension to turn it into something you can click on. 您可以使用.command扩展.command其转换为可以单击的内容。 Just be sure to save it as text-only (Format -> Make Plain Text in TextEdit). 只需确保将其保存为纯文本(格式化 - >在TextEdit中创建纯文本)。

make a file switchhideshow.command with the following content: 使用以下内容创建一个文件switchhideshow.command:

#!/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

then: chmod a+x switchhideshow.command 然后: chmod a+x switchhideshow.command

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. 它描述了如何调用shell脚本以显示Automator Actions中的隐藏文件。

Have a look at Platypus ; 看看鸭嘴兽 ; it will wrap up many different kinds of scripts into proper OS X applications. 它会将许多不同类型的脚本包装到适当的OS X应用程序中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM