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

### 介绍

不知道小伙伴们有没有发现这样一件事情: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 -> 服务 -> 新建文档来在当前位置新建一个无格式文档了。当然,你也可以自己设置快捷键让新建文档更加方便。

Mac OS下新建文本文档的更多相关文章

  1. Windows右击无新建文本文档怎么办

    右击无新建文本文档2008-07-26 16:51 刚在网上找的,在运行项输入notepad,把下面的复制进去,然后保存为123.reg,双击导入. REGEDIT4 [HKEY_CLASSES_RO ...

  2. Win7如何自定义鼠标右键菜单 添加新建文本文档

    鼠标右键新建文本文档.reg REGEDIT4 [HKEY_CLASSES_ROOT\.txt] @="txtfile" "Content Type"=&quo ...

  3. 电脑右键新建文本文档(txt)消失的解决办法

    其实只需要一个注册表就可以了 下载地址http://pan.baidu.com/s/1hr7r0fM 拿走不谢! 注册表的内容是这样的,你也可以新建一个文件把后缀名改成.reg然后把下面的内容copy ...

  4. java代码---------实现File的目录下创建文本文档

    总结:虽然他没教给我们很多,但是他已经很棒了 package com.a.b; import java.io.*; public class dd { public static void main( ...

  5. 桌面右键没有新建txt文本文档的快捷方式、

    先新建一个word文档,然后将后缀名改为 TXT. 在里面输入:Windows Registry Editor Version 5.00 [HKEY_CLASSES_ROOT\.txt] @=&quo ...

  6. Java 把一个文本文档的内容复制到另一个文本文档

    src.txt放在工程目录下,dest.txt可创建,也可不创建.一旦运行程序,如果dest.txt不存在,将自行创建这个文本文档,再将src.txt中的内容复制到dest.txt import ja ...

  7. mac os 下搭建android开发环境

    mac os 下搭建android开发环境 周银辉 mac os 下搭建android环境比较方便, 如下几个步骤: 1,安装jdk 先搞清楚自己是否已经安装,在命令行下:java -version, ...

  8. c#读取文本文档实践3-写入到文本本文档

    首先通过File.ReadAllLines()方法读入文本文档中内容并返回字符串数组contents,这样每行数据就成为了这个字符串数组contents的一个元素,再利用split()方法将每一个元素 ...

  9. c#读取文本文档实践1-File.ReadAllLines()

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.I ...

随机推荐

  1. 微软2016校园招聘在线笔试第二场 题目1 : Lucky Substrings

    时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 A string s is LUCKY if and only if the number of different ch ...

  2. ubunut jdk 配置

    sudo mv jdk1.7.0_10 /usr/lib/jvm/ sudo gedit /etc/profile 在profile中加入下面内容: export JAVA_HOME=/usr/lib ...

  3. 【Postman】接口测试工具:在谷歌浏览器安装插件方法以及使用说明

    安装插件方法: <如何在谷歌浏览器chrome中离线安装.crx扩展程序的三种方法?> <postman chrome插件的安装与使用> 下载地址:http://www.cnp ...

  4. 每天学习30分钟新知识之html教程1

    版本 年份 HTML 1991 HTML+ 1993 HTML 2.0 1995 HTML 3.2 1997 HTML 4.01 1999 XHTML 1.0 2000 HTML5 2012 XHTM ...

  5. Java学习篇之---json-lib(Maven)

    json-lib(Maven) java中用于解释json的主流工具有org.json.json-lib与gson.本篇文章介绍json-lib. 项目中要用到json-lib.在pom.xml文件里 ...

  6. PHP-Manual的学习----【入门指引】

    2017年6月27日17:03:53 笔记:简介    PHP是什么?    PHP能做什么?1.PHP("PHP: Hypertext Preprocessor",超文本预处理器 ...

  7. visual studio code (vscode)像 sublime text 的 ctrl+d 一样多光标选中

    快捷键是 ctrl+m ,返回上一个选中时ctrl+u. 文件 ==>首选项 ==>键盘快捷键() 里面可以查到,下一个是“将选择添加到下一个查找匹配项”,返回上一个是“cursorund ...

  8. POJ 1694 An Old Stone Game【递归+排序】

    链接: http://poj.org/problem?id=1694 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=27454#probl ...

  9. hdu 3549 Flow Problem【最大流增广路入门模板题】

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=3549 Flow Problem Time Limit: 5000/5000 MS (Java/Others ...

  10. Pipeline outbound

    netty源码死磕8 Pipeline outbound 出站流程揭秘 1. Pipeline outbound流程 1.1. 出站的定义 简单回顾一下. 出站(outbound) 操作,通常是处于上 ...