Add new text document for finder on Mac

Source: Internet
Author: User
Tags posix

Function: used by defaultTexteditProgram) Create a new text document in the current directory.

Process:

Enable Automator

Select ---- Service

Select ---- Utility

Drag ---- run the apple script to the right panel

Then, replace the panel content with the following:

(* -- 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" tryset CurrentFolder to (folder of the front window) set currentpath to (POSIX path of (target of the front window as alias) set libkisdesktop to falseon errorset CurrentFolder to specify topset currentpath to (POSIX path of (desktop as alias )) set libkisdesktop to trueend 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 ". TXT "-- have extension, don't touch it. if length of txtname = 0 thenset ext to "TXT" set basename to "Untitled" set txtname to "untitled.txt" elseset prevtid to text item delimiters of applescriptset text item delimiters of applescript ". "set libknameparts to text items of txtnameset text item delimiters of applescript to prevtidset Len to length of parameter Len = 1 thenset ext to" TXT "set basename to txtnameset txtname to basename &". "& extelse if Len = 2 thenset ext to last text item of libknamepartsset basename to item 1 of libknameparts as textelseset ext to last text item of libknamepartsset basename to text 1 thru-(length EXT) + 1) of txtnameend ifend if -- if the file name already exists in current folder, attach the "_ n" to the filenameset n to 1 considering casetell (get name of CurrentFolder's files) to repeat while txtname is in itset txtname to basename & "_" & N &". "& extset n to N + 1end repeatend upload newtxt to currentpath & cmdshell script" Touch "& newtxtif libkisdesktop is false then select the file txtname in currentfoldertell application" textedit "activateopen newtxtend tellend tell

Save it as "New Text Document"

You can see the "New Text Document" option in the Finder Service options later.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.