Macbook: How to create a new text file in Finder (step by step)

Grassroot Engineer
3 min readJul 15, 2021

--

ใน Windows ถ้าเราจะสร้างไฟล์ใหม่ ก็แค่ right click > new file ได้เลย
แต่ใน Mac มันทำไม่ได้นี่สิ, มีแต่ New Folder แต่ไม่มี New File

ถ้า Windows ก็ทำแบบนี้ได้เลย

วิธีที่ programmer ใช้คือ touch newfile.txt ผ่าน command line แต่สำหรับ users ทั่วไปที่ไม่ถนัด มาลอง configure Mac กันดีกว่าคับ

10 ขั้นตอนสร้าง New Text File in Finder

  1. เปิด Automator > File > New

2. เลือก Quick Action

3. เลือก Workflow receives = no input in Finder

4. ต่อไปให้พิมพ์คำว่า javas เพื่อเรียกโครง function js ขึ้นมา

5. พิมพ์ code js ชุดนี้เข้าไป

function run(input, parameters) {
var finder = Application('Finder');
finder.includeStandardAdditions = true;
var currentPath = decodeURI(finder.windows[0].target().url().slice(7));
return currentPath;
}

และ cmd + s เพื่อ save ในชื่อ New Text File

6. ให้พิมพ์ set va และ drage เพื่อสร้างโครงของ variable ดังรูป

7. สร้าง variable ชื่อว่า currentPath ดังรูป

8. สร้างส่วนของ New Text File

ถึงขั้นตอนนี้ เราจะสร้าง New Text File ขึ้นมาจาก Finder ได้แล้ว แต่จะมี currentPath อยู่ด้านในด้วย

9. เนื่องจาก New File ที่ได้จะมีข้อความของ currentPath อยู่ด้านในด้วย เราจึงต้องเพิ่ม js พร้อมกับ ignore input

10. ไฟล์ js ที่สร้างขึ้นมาใหม่ ให้ return empty string เรียบร้อยแล้วก้อ Save อีกรอบ

จบแล้วใน 10 ขั้นตอนสร้าง New Text File ใน Finder นะคับ ส่วนวิธีการเรียกใช้ทำได้ 2 แบบคือ

  • เรียกผ่าน Finder > Services > New Text File ได้เลย (แต่จะไม่ค่อยสะดวกเท่าไหร่นัก)
  • สร้าง Shortcut มาเรียกดีกว่า โดยเข้าไปที่ Keyboard > Shortcuts > Services > มองหา New Text File
Demo how to use.

แล้วพบกันใหม่คับ

For your references in UI.

--

--

Grassroot Engineer
Grassroot Engineer

Written by Grassroot Engineer

ATM engineer who is interested in CODING and believe in EFFORT. — https://grassrootengineer.com

Responses (1)