Gav*_*ock 56
我使用了几个脚本:
dup(带工作目录的新窗口):
#!/bin/sh
pwd=`pwd`
osascript -e "tell application \"Terminal\" to do script \"cd $pwd; clear\"" > /dev/null
Run Code Online (Sandbox Code Playgroud)
和tup (具有相同工作目录的新选项卡):
#!/bin/sh
pwd=`pwd`
osascript -e "tell application \"Terminal\"" \
-e "tell application \"System Events\" to keystroke \"t\" using {command down}" \
-e "do script \"cd $pwd; clear\" in front window" \
-e "end tell"
> /dev/null
Run Code Online (Sandbox Code Playgroud)
好吧,按照我的方式,我再次回答我自己的问题(至少已经接近回答它了)
我发现了一个比上面的脚本更简洁的脚本(由Dan Benjamin提供)似乎可以解决问题,尽管两个脚本在成功完成之前都会输出类似的错误。我已经通过在脚本末尾添加clear来解决这个问题,所以这不是什么大问题。
我说我几乎已经解决了我自己的问题,因为我的目标是找到一种方法来使用 Apple-t 键命令来完成此任务,该命令已成为我肌肉记忆中的新选项卡的快捷方式,这要归功于无数个小时在各种网络浏览器中。对于像 Dan 这样的脚本,我能做到的最好的就是 t-return,这不是最大的区别,但足够大,以至于每次我发出上述命令时我都会有点厌烦。我知道,我应该放手......但我不能,这可能就是我最初陷入困境的原因,无休止地摆弄电脑。我离题了,这是我正在使用的脚本:
#!/bin/sh
# Make a new OS X Terminal tab with the current working directory.
if [ $# -ne 1 ]; then
PATHDIR=`pwd`
else
PATHDIR=$1
fi
/usr/bin/osascript <<EOF
activate application "Terminal"
tell application "System Events"
keystroke "t" using {command down}
end tell
tell application "Terminal"
repeat with win in windows
try
if get frontmost of win is true then
do script "cd $PATHDIR; clear" in (selected tab of win)
end if
end try
end repeat
end tell
EOF
clear
Run Code Online (Sandbox Code Playgroud)
为了完整起见,如果省略尾随清除,则会在请求窗口上吐出错误:
2009-10-20 01:30:38.714 osascript[20862:903] Error loading /Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types: dlopen(/Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types, 262): no suitable image found. Did find:
/Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types: no matching architecture in universal wrapper
osascript: OpenScripting.framework - scripting addition "/Library/ScriptingAdditions/Adobe Unit Types.osax" declares no loadable handlers.
tab 2 of window id 13942
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
19096 次 |
| 最近记录: |