Mac添加新建文本文档

2023-10-24 09:33
文章标签 mac 新建 文本文档

本文主要是介绍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的服务选项中看到”新建文本文档“选项。

这篇关于Mac添加新建文本文档的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/274271

相关文章

IDEA中新建/切换Git分支的实现步骤

《IDEA中新建/切换Git分支的实现步骤》本文主要介绍了IDEA中新建/切换Git分支的实现步骤,通过菜单创建新分支并选择是否切换,创建后在Git详情或右键Checkout中切换分支,感兴趣的可以了... 前提:项目已被Git托管1、点击上方栏Git->NewBrancjsh...2、输入新的分支的

如何在Mac上彻底删除Edge账户? 手动卸载Edge浏览器并清理残留文件技巧

《如何在Mac上彻底删除Edge账户?手动卸载Edge浏览器并清理残留文件技巧》Mac上的Edge账户里存了不少网站密码和个人信息,结果同事一不小心打开了,简直尴尬到爆炸,想要卸载edge浏览器并清... 如果你遇到 Microsoft Edge 浏览器运行迟缓、频繁崩溃或网页加载异常等问题,可以尝试多种方

Mac系统下卸载JAVA和JDK的步骤

《Mac系统下卸载JAVA和JDK的步骤》JDK是Java语言的软件开发工具包,它提供了开发和运行Java应用程序所需的工具、库和资源,:本文主要介绍Mac系统下卸载JAVA和JDK的相关资料,需... 目录1. 卸载系统自带的 Java 版本检查当前 Java 版本通过命令卸载系统 Java2. 卸载自定

如何确定哪些软件是Mac系统自带的? Mac系统内置应用查看技巧

《如何确定哪些软件是Mac系统自带的?Mac系统内置应用查看技巧》如何确定哪些软件是Mac系统自带的?mac系统中有很多自带的应用,想要看看哪些是系统自带,该怎么查看呢?下面我们就来看看Mac系统内... 在MAC电脑上,可以使用以下方法来确定哪些软件是系统自带的:1.应用程序文件夹打开应用程序文件夹

Mac备忘录怎么导出/备份和云同步? Mac备忘录使用技巧

《Mac备忘录怎么导出/备份和云同步?Mac备忘录使用技巧》备忘录作为iOS里简单而又不可或缺的一个系统应用,上手容易,可以满足我们日常生活中各种记录的需求,今天我们就来看看Mac备忘录的导出、... 「备忘录」是 MAC 上的一款常用应用,它可以帮助我们捕捉灵感、记录待办事项或保存重要信息。为了便于在不同

电脑蓝牙连不上怎么办? 5 招教你轻松修复Mac蓝牙连接问题的技巧

《电脑蓝牙连不上怎么办?5招教你轻松修复Mac蓝牙连接问题的技巧》蓝牙连接问题是一些Mac用户经常遇到的常见问题之一,在本文章中,我们将提供一些有用的提示和技巧,帮助您解决可能出现的蓝牙连接问... 蓝牙作为一种流行的无线技术,已经成为我们连接各种设备的重要工具。在 MAC 上,你可以根据自己的需求,轻松地

如何关闭Mac的Safari通知? 3招教你关闭Safari浏览器网站通知的技巧

《如何关闭Mac的Safari通知?3招教你关闭Safari浏览器网站通知的技巧》当我们在使用Mac电脑专注做一件事情的时候,总是会被一些消息推送通知所打扰,这时候,我们就希望关闭这些烦人的Mac通... Safari 浏览器的「通知」功能本意是为了方便用户及时获取最新资讯,但很容易被一些网站滥用,导致我们

Android与iOS设备MAC地址生成原理及Java实现详解

《Android与iOS设备MAC地址生成原理及Java实现详解》在无线网络通信中,MAC(MediaAccessControl)地址是设备的唯一网络标识符,本文主要介绍了Android与iOS设备M... 目录引言1. MAC地址基础1.1 MAC地址的组成1.2 MAC地址的分类2. android与I

如何在Mac上安装并配置JDK环境变量详细步骤

《如何在Mac上安装并配置JDK环境变量详细步骤》:本文主要介绍如何在Mac上安装并配置JDK环境变量详细步骤,包括下载JDK、安装JDK、配置环境变量、验证JDK配置以及可选地设置PowerSh... 目录步骤 1:下载JDK步骤 2:安装JDK步骤 3:配置环境变量1. 编辑~/.zshrc(对于zsh

微信公众号脚本-获取热搜自动新建草稿并发布文章

《微信公众号脚本-获取热搜自动新建草稿并发布文章》本来想写一个自动化发布微信公众号的小绿书的脚本,但是微信公众号官网没有小绿书的接口,那就写一个获取热搜微信普通文章的脚本吧,:本文主要介绍微信公众... 目录介绍思路前期准备环境要求获取接口token获取热搜获取热搜数据下载热搜图片给图片加上标题文字上传图片