我们如何编写Alfred工作流来打开从finder到vim编辑器的文件?
这是我第一次尝试在阿尔弗雷德中创建工作流。我还在学习,想从一个简单的工作流程开始。
在这里,我首先创建了热键和关键字。
Open the Alfred3
Go to Workflows
Click + sign at the bottom left sidebar
Choose Blak Workflow
Name: Vim Launcher
Description: Opens a file in the terminal inside vim editor
1. Right-click > Trigger > press cmd-alt-v
2. Right-click > Inputs > Keyword > open in vim and title also open in vim
3. Right-click > Actions > Run NSAppleScipt在Run NSAppleScipt中复制和粘贴以下内容
on alfred_script(q)
tell application "Terminal"
activate
do script "vim '" & q & "'"
end tell
end alfred_script此工作流工作,但打开两个终端,而不是一个。我们如何解决这个问题,使它只打开一个窗口?
工作流摘要如下所示。

发布于 2018-04-13 02:30:17
你想要一个终端指挥动作。
只需将此对象连接到触发器并在其上使用vim "{query}"即可。
编辑:
我正在编辑答案,回答一条评论,问一个后续问题:
工作流现在为每个文件创建了新的termnial,如果一个终端已经在运行,我们可以在同一个终端中打开它吗?
在这种情况下,可以使用Run NSAppleScript对象的不同之处,即我们必须指定运行do script的位置,因为如果没有指定位置,它总是打开一个新窗口:
on alfred_script(q)
tell application "Terminal"
if not (exists window 1) then reopen
activate
do script "vim '" & q & "'" in window 1
end tell
end alfred_scripthttps://stackoverflow.com/questions/49798366
复制相似问题