分享我的一个日常操作,我习惯性在当前目录下创建文件,然后打开编辑,但是 MacOS 没有创建文件的选项。但是我们可以通过自带的 Automator 创建工作流,然后绑定快捷键来实现这个目的。以下是我的操作步骤。同时我在 B 站录制了视频,食用更香,欢迎各位前往观看,记得三连哦!
视屏地址: https://www.bilibili.com/video/BV1Vg4y1872j
操作步骤:
Automator
并选择Quick Action
。Workflow receives current
选择no input
然后把any application
改为Finder.app
。Actions
搜索Run AppleScript
并将其拖到右侧空白区域。set file_name to "untitled"
set file_ext to ".txt"
set is_desktop to false
-- get folder path and if we are in desktop (no folder opened)
try
tell application "Finder"
set this_folder to (folder of the front Finder window) as alias
end tell
on error
-- no open folder windows
set this_folder to path to desktop folder as alias
set is_desktop to true
end try
-- get the new file name (do not override an already existing file)
tell application "System Events"
set file_list to get the name of every disk item of this_folder
end tell
set new_file to file_name & file_ext
set x to 1
repeat
if new_file is in file_list then
set new_file to file_name & " " & x & file_ext
set x to x + 1
else
exit repeat
end if
end repeat
-- create and select the new file
tell application "Finder"
activate
set the_file to make new file at folder this_folder with properties {name:new_file}
if is_desktop is false then
reveal the_file
else
select window of desktop
set selection to the_file
delay 0.1
end if
end tell
-- press enter (rename)
tell application "System Events"
tell process "Finder"
keystroke return
end tell
end tell
~/Library/Services
)。Keyboard
打开对话框。Shortcuts
标签页的Services
中找到我们刚才保存的文件名并配置快捷键。::: warning 注意
此时在Finder
中使用快捷键可能会现警告。我们还需要在系统设置中的Seurity & Privacy
里面把Privacy
标签页Accessibility
选项中的Finder
勾选才行。
:::
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.