Mac添加新建文本文档

功能:默认使用TextEdit(自带文本文档程序)在当前目录建立新文本文档。

过程:

打开automator

选择----服务

选取----实用工具

拖动----运行apple script 到右边的面板中

然后把面板内容替换如下:

[javascript]  view plain copy
  1. (*  
  2. --Author: Libok Zhou (libk.8800.org, libkhorse@gmail.com). Feel free to contact me if you have questions about this script  
  3. --Usage: This script is used for Automator to add an "new text file" to the context menu,   
  4.          when you want to create a new text file in current folder of Finder  
  5. *)  
  6. tell application "Finder"  
  7.     try  
  8.         set currentFolder to (folder of the front window)  
  9.         set currentPath to (POSIX path of (target of the front window as alias))  
  10.         set libkIsDeskTop to false  
  11.     on error  
  12.         set currentFolder to desktop  
  13.         set currentPath to (POSIX path of (desktop as alias))  
  14.         set libkIsDeskTop to true  
  15.     end try  
  16.     (*  
  17.     set currentPath to (POSIX path of (target of the front window as alias))  
  18.     set currentFolder to (folder of the front window)  
  19.     *)  
  20.       
  21.     set txtName to text returned of (display dialog "Please enter the text name, " default answer "untitled.txt")  
  22.       
  23.     --if txtName is empty using "untitled.txt" as default  
  24.     --no trailing extension, suffix with ".txt"  
  25.     --have extension, don't touch it.  
  26.     if length of txtName = 0 then  
  27.         set ext to "txt"  
  28.         set baseName to "untitled"  
  29.         set txtName to "untitled.txt"  
  30.     else  
  31.         set prevTID to text item delimiters of AppleScript  
  32.         set text item delimiters of AppleScript to "."  
  33.         set libkNameParts to text items of txtName  
  34.         set text item delimiters of AppleScript to prevTID  
  35.           
  36.         set len to length of libkNameParts  
  37.         if len = 1 then  
  38.             set ext to "txt"  
  39.             set baseName to txtName  
  40.             set txtName to baseName & "." & ext  
  41.         else if len = 2 then  
  42.             set ext to last text item of libkNameParts  
  43.             set baseName to item 1 of libkNameParts as text  
  44.         else  
  45.             set ext to last text item of libkNameParts  
  46.             set baseName to text 1 thru -((length of ext) + 1) of txtName  
  47.         end if  
  48.     end if  
  49.       
  50.       
  51.       
  52.     -- if the file name already exists in current folder, attach the "_n" to the filename  
  53.     set n to 1  
  54.     considering case  
  55.         tell (get name of currentFolder's files) to repeat while txtName is in it  
  56.             set txtName to baseName & "_" & n & "." & ext  
  57.             set n to n + 1  
  58.         end repeat  
  59.     end considering  
  60.       
  61.       
  62.     set newTxt to currentPath & txtName  
  63.     do shell script "touch " & newTxt  
  64.     if libkIsDeskTop is false then select the file txtName in currentFolder  
  65.     tell application "TextEdit"  
  66.         activate  
  67.         open newTxt  
  68.     end tell  
  69.       
  70. end tell  

然后保存为:“新建文本文档“

以后即可在finder的服务选项中看到”新建文本文档“选项。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值