Terminal scripting in OSX

爱⌒轻易说出口 提交于 2019-12-10 14:00:52

问题


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

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.

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

Thanks guys


回答1:


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

then: 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.




回答2:


You can use the .command extension to turn it into something you can click on. Just be sure to save it as text-only (Format -> Make Plain Text in TextEdit).




回答3:


Have a look at Platypus; it will wrap up many different kinds of scripts into proper OS X applications.



来源:https://stackoverflow.com/questions/4187124/terminal-scripting-in-osx

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!