博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
mac 为finder添加 新建文本文档
阅读量:5874 次
发布时间:2019-06-19

本文共 2371 字,大约阅读时间需要 7 分钟。

  hot3.png

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

过程:

打开automator

选择----服务

选取----实用工具

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

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

(*--Author: Libok Zhou (libk.8800.org, libkhorse@gmail.com). Feel free to contact me if you have questions about this script--Usage: This script is used for Automator to add an "new text file" to the context menu, 	     when you want to create a new text file in current folder of Finder*)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 txtName to text returned of (display dialog "Please enter the text name, " default answer "untitled.txt")		--if txtName is empty using "untitled.txt" as default	--no trailing extension, suffix with ".txt"	--have extension, don't touch it.	if length of txtName = 0 then		set ext to "txt"		set baseName to "untitled"		set txtName to "untitled.txt"	else		set prevTID to text item delimiters of AppleScript		set text item delimiters of AppleScript to "."		set libkNameParts to text items of txtName		set text item delimiters of AppleScript to prevTID				set len to length of libkNameParts		if len = 1 then			set ext to "txt"			set baseName to txtName			set txtName to baseName & "." & ext		else if len = 2 then			set ext to last text item of libkNameParts			set baseName to item 1 of libkNameParts as text		else			set ext to last text item of libkNameParts			set baseName to text 1 thru -((length of ext) + 1) of txtName		end if	end if				-- 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 & "." & ext			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	tell application "TextEdit"		activate		open newTxt	end tell	end tell
然后保存为:“新建文本文档“

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

转载于:https://my.oschina.net/dake/blog/196709

你可能感兴趣的文章
初学者一些常用的SQL语句(二)
查看>>
自我成长
查看>>
论文阅读笔记五十三:Libra R-CNN: Towards Balanced Learning for Object Detection(CVPR2019)
查看>>
ASP.Net Web 服务 – 如何使用会话状态
查看>>
Jetty的JNDI数据源
查看>>
angularjs modal模态框----创建可拖动的指令
查看>>
oracle 视图权限 oracle 创建视图权限不足( ORA-01031: 权限不足)
查看>>
Uva 11218 - KTV
查看>>
队列的链式存储结构
查看>>
Linux之特殊的环境变量IFS以及如何删除带有空格的目录
查看>>
Python文摘:Requests (Adavanced Usage)
查看>>
IDEA 运行maven命令时报错: -Dmaven.multiModuleProjectDirectory system propery is not set
查看>>
无插件,跨平台,基于WebGL的三维地球来了!!!
查看>>
通过反射初始化Class值【原】
查看>>
陶哲轩实分析引理10.4.1:反函数定理
查看>>
Python文摘:Mixin
查看>>
几十万人同时在线的直播间聊天,如何设计服务端架构?
查看>>
VIM Emacs 临时获得权限(:w !sudo tee %)
查看>>
highcharts.js两种数据绑定方式和异步加载数据的使用
查看>>
python学习——函数及其参数
查看>>