Creating text or markdown file in a folder (MacOS)
Looking for an easy solution to create a text or markdown file in the folder that you are viewing in MacOS?
Looking for an easy solution to create a text or markdown file in the folder that you are viewing in MacOS? A search of the web reveals third party apps as well as some old methods that only result in a text file.
This solution relies on the script editor built in to MacOS - Apple support article
To learn more about Apple scripts, do a search. Here’s some basics (AI generated):
Enabling Scripts on macOS
To enable and run scripts on macOS, you can use AppleScript or shell scripts. Here’s how to set them up:
AppleScript
- Open Script Editor: Find it in Applications > Utilities.
- Create Your Script: Write your AppleScript code in the editor.
- Enable Script Menu:
- Go to Script Editor > Preferences.
- Check “Show Script menu in menu bar” and “Show Computer scripts”.
- Run Your Script: You can now access your scripts from the menu bar.
The Script to create a text or markdown file
This is an easy script to create a text or markdown file in the folder that you are viewing on MacOS.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
try
tell application "Finder"
if (count of windows) = 0 then
set targetFolder to desktop
else
set targetFolder to (the target of the front window)
end if
set targetPath to POSIX path of (targetFolder as alias)
end tell
-- Create the markdown file
do shell script "echo '# untitled' > '" & targetPath & "untitled.md'"
tell application "Finder"
update targetFolder
end tell
on error errMsg
display dialog "Error creating file: " & errMsg buttons {"OK"} default button 1
end try
If you prefer a text file, change the extension (.md) to .txt