我正在尝试创建一个keyhortcut来打开当前文件夹中的终端。环顾四周,我发现这个代码创建了一个服务(添加了这个服务的快捷方式的部分就解决了),只添加了一些东西是“; clear”和一些“激活”所以它显示了
on run {input, parameters}
tell application "Finder"
activate
set myWin to window 1
set theWin to (quoted form of POSIX path of (target of myWin as alias))
tell application "Terminal"
activate
tell window 1
activate
do script "cd " & theWin & ";clear"
end tell
end tell
end tell
return input
end run
这不符合我的意愿。
的烦恼:
这是我对Applescript的第一次尝试,所以如果错误很明显,我就是看不到它
提前致谢
答案 0 :(得分:9)
do script
命令已在终端中打开一个窗口。试试这种方式:
tell application "Finder" to set theSel to selection
tell application "Terminal"
set theFol to POSIX path of ((item 1 of theSel) as text)
if (count of windows) is not 0 then
do script "cd " & quoted form of theFol & ";clear" in window 1
else
do script "cd " & quoted form of theFol & ";clear"
end if
activate
end tell
答案 1 :(得分:8)
我更喜欢重新开放的方法......
tell application "Finder" to set currentFolder to target of front Finder window as text
set theWin to currentFolder's POSIX path
tell application "Terminal"
if not (exists window 1) then reopen
activate
do script "cd " & quoted form of theWin & ";clear" in window 1
end tell