Mac OS下新建文本文档

---恢复内容开始---

### 介绍

不知道小伙伴们有没有发现这样一件事情:Mac下没有新建文本文档!如果你恰好经常需要新建类似于.cpp,.in,.out等文件的话,每次终端用一堆$ cd命令再加上一句$ touch,简直是苦不堪言。好在有同样苦衷的网友早已找到了解决方案,那就是利用系统自带的Automator。

使用

1.打开实用程序 -> Automator,新建一个服务(Service).

2.从左边Library栏里找到Run Applescript选项,把它拖到右边的窗口里.

3.把右边窗口上端的Service receives选项设置为no input

4.输入以下代码:

tell application "Finder"
	try
		set currentFolder to (folder of the front window)
		set currentPath to (POSIX path of (target of the front window as alias))
		set libkIsDeskTop to false
	on error
		set currentFolder to desktop
		set currentPath to (POSIX path of (desktop as alias))
		set libkIsDeskTop to true
	end try
	(*
	set currentPath to (POSIX path of (target of the front window as alias))
	set currentFolder to (folder of the front window)
	*)
	
	set baseName to "Untitled"
	set txtName to baseName
	
	-- if the file name already exists in current folder, attach the "_n" to the filename
	set n to 1
	considering case
		tell (get name of currentFolder's files) to repeat while txtName is in it
			set txtName to baseName & "_" & n
			set n to n + 1
		end repeat
	end considering
	
	
	set newTxt to currentPath & txtName
	do shell script "touch " & newTxt
	if libkIsDeskTop is false then select the file txtName in currentFolder
	
end tell

5.按Command+s来保存,在对话框中输入“新建文档”

完成

此时,在Finder内就可以通过Finder -> 服务 -> 新建文档来在当前位置新建一个无格式文档了。当然,你也可以自己设置快捷键让新建文档更加方便。

---恢复内容结束---

### 介绍

不知道小伙伴们有没有发现这样一件事情:Mac下没有新建文本文档!如果你恰好经常需要新建类似于.cpp,.in,.out等文件的话,每次终端用一堆$ cd命令再加上一句$ touch,简直是苦不堪言。好在有同样苦衷的网友早已找到了解决方案,那就是利用系统自带的Automator。

使用

1.打开实用程序 -> Automator,新建一个服务(Service).

2.从左边Library栏里找到Run Applescript选项,把它拖到右边的窗口里.

3.把右边窗口上端的Service receives选项设置为no input

4.输入以下代码:

tell application "Finder"
	try
		set currentFolder to (folder of the front window)
		set currentPath to (POSIX path of (target of the front window as alias))
		set libkIsDeskTop to false
	on error
		set currentFolder to desktop
		set currentPath to (POSIX path of (desktop as alias))
		set libkIsDeskTop to true
	end try
	(*
	set currentPath to (POSIX path of (target of the front window as alias))
	set currentFolder to (folder of the front window)
	*)
	
	set baseName to "Untitled"
	set txtName to baseName
	
	(* if the file name already exists in current folder, attach the "_n" to the filename *)
	set n to 1
	considering case
		tell (get name of currentFolder's files) to repeat while txtName is in it
			set txtName to baseName & "_" & n
			set n to n + 1
		end repeat
	end considering
	
	
	set newTxt to currentPath & txtName
	do shell script "touch " & newTxt
	if libkIsDeskTop is false then select the file txtName in currentFolder
	
end tell

5.按Command+s来保存,在对话框中输入“新建文档”

完成

此时,在Finder内就可以通过Finder -> 服务 -> 新建文档来在当前位置新建一个无格式文档了。当然,你也可以自己设置快捷键让新建文档更加方便。

posted @ 2015-12-04 00:28  Hist!  阅读(1248)  评论(0编辑  收藏  举报