alias text='open -a /Applications/TextWrangler.app'
I think you want a full-fledged shell script rather than just an alias. Make a file with these contents:
if [ -e "$1" ]; then
open -a TextWrangler -- "$1"
else
touch "$1"
open -a TextWrangler -- "$1"
fi
Save it as text somewhere
in your PATH and chmod it to be executable and you're golden.
If you really want to make it so that the file doesn't exist if you don't save it, that's trickier. I think you'll have to do something like this:
if [ -e "$1" ]; then
open -a TextWrangler -- "$1"
else
touch "$1"
open -a TextWrangler -- "$1"
sleep 1
rm "$1"
fi
This will actually create the file and then delete it one second later. The app will still have the file open, though, so that when you save it will be recreated.
How about just create a function instead of an alias in your starup file (.bashrc, .profile etc).
newf() {
echo "$1" | xargs touch; open -a "/Applications/TextWrangler.app" "$1"
}
Once added, source your startup script and just do the following to use this -
newf dummyfile.txt
and Text Wrangler will pop up with an empty file called dummyfile.txt.
转载:http://stackoverflow.com/questions/8609197/osx-open-command-to-create-new-files-with-an-app
本文介绍如何在OSX系统中通过shell脚本或函数的方式启动TextWrangler来创建和打开文件。提供了两种方法,一种是创建一个可执行脚本来实现功能,另一种是在启动文件中定义一个函数来达到同样的目的。
1万+

被折叠的 条评论
为什么被折叠?



