Mac OS下新建文本文档

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

介绍

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

使用

1.打开实用程序 -> Automator,新建一个服务(Service).
794087-20151204002532205-1956479024.png
794087-20151204002733955-689201166.png

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

3.把右边窗口上端的Service receives选项设置为no input
794087-20151204002041799-2065326141.png

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来保存,在对话框中输入“新建文档”

794087-20151204002347799-1791963025.png

完成

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

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

### 介绍

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

使用

1.打开实用程序 -> Automator,新建一个服务(Service).
794087-20151204002532205-1956479024.png
794087-20151204002733955-689201166.png

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

3.把右边窗口上端的Service receives选项设置为no input
794087-20151204002041799-2065326141.png

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来保存,在对话框中输入“新建文档”

794087-20151204002347799-1791963025.png

完成

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

转载于:https://www.cnblogs.com/Hist/p/5018146.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值