开发者

Shell Script to Create Blank File in Working Directory (Mac OS X)

I want to write a shell script that you can drop anywhere and when you open it, it simply creates a new file in that directory. So far I have this:

#!/bin/bash
BASEDIR=$(dirname $0)
touch $BASEDIR/untitled

Which works, except there's two things I'd like to do to it that I have no idea how to.

  1. Is there a way to get Finder to focus on it aft开发者_如何学Pythoner creating it? (like how Windows and most Linux distros do when you do Create New File from the right click context menu)

  2. How can I make the script not open terminal each time you click on it? Would I need to make it an ".app"?

So you get an idea of where Im putting it, Im putting it here:

Shell Script to Create Blank File in Working Directory (Mac OS X)

so that I can create a new file anywhere.


You should use AppleScript for this instead of bash. I believe you can use AppleScript to both create the file and select the file in the Finder.

To create a file in AppleScript, for example:

do shell script "touch /foo.txt"


Maybe you should look at Jonas' New Txt File Here script:

http://wisser.me/software/#NewTextFileHere


I have created utility to create file in top window of finder.

Have a look at it.

I have also kept the applescript in article.

http://www.think-1st.com/mac-osx-create-new-file-from-finder-applescript/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜