Macos在文件夹中快速打开终端
使用自动操作+AppleScript的方法
- 打开
自动操作
- 新建应用程序
- 切换实用工具
- 运行AppleScript
- 贴代码
我这里使用iTerm2
,如果你使用默认终端,直接把iTerm
改成Terminal
就行了,可以看一下我的代码,逻辑很简单。
on run {input, parameters}
tell application "Finder"
set pathList to (quoted form of POSIX path of (folder of the front window as alias))
set command to "clear; cd " & pathList
end tell
tell application "System Events"
# some versions might identify as "iTerm2" instead of "iTerm"
set isRunning to (exists (processes where name is "iTerm")) or (exists (processes where name is "iTerm2"))
end tell
tell application "iTerm"
activate
set hasNoWindows to ((count of windows) is 0)
if isRunning and hasNoWindows then
create window with default profile
end if
select first window
tell the first window
if isRunning and hasNoWindows is false then
create window with default profile
end if
tell current session to write text command
end tell
end tell
end run
This post is licensed under
CC BY 4.0
by the author.