如何告诉终端在窗口中执行脚本,我刚刚打开
我尝试了这个
tell application "Terminal"
set custom to open "/Users/jredfox/Desktop/h.terminal"
do script "/Users/jredfox/Desktop/test.sh" in custom
activate
end tell
只是说失败了。我不想使用硬码窗口1,因为窗口1并不总是是我刚刚打开的自定义窗口。
我的目标是用自定义配置文件打开终端,然后在其中运行一个脚本。我是AppleScript的新手,不明白为什么这不起作用。我想使用刚刚打开的窗口,而不是窗口1,该窗口有时会失败,并且不支持多个窗口
I tried this
tell application "Terminal"
set custom to open "/Users/jredfox/Desktop/h.terminal"
do script "/Users/jredfox/Desktop/test.sh" in custom
activate
end tell
this just says failed. I don't want to hard code window 1 because window 1 isn't always going to be the custom window I just opened.
My Goal is to open up the terminal with a custom profile then run a script inside of it. I am new to AppleScript and don't understand why this isn't working. I want to use the window that just got opened not window 1 which fails sometimes and doesn't support multiple windows
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
编程时,一个有用的习惯是关注您添加任何陌生代码后实际发生的事情。在AppleScript中执行此操作的快速方法是
Result
变量。命令的返回值转到结果
,但您也可以明确设置它。结果中的值
在脚本编辑器的默认窗口的底部显示。例如,我仅在您的脚本的这一部分粘贴了一个调整:
执行时间太长了,
结果
是是缺失值
。因此,马上,我们知道什么都不会起作用。但为什么?我从“文件”菜单中选择了“打开字典……”,然后选择终端。终端似乎使用
open
命令,这意味着默认情况下它需要一个苹果路径,而不是posix路径。好吧,它立即开始打开,但即使是
result
不正确,这也无济于事。我认为Open
命令似乎没有返回对新窗口的引用,正如您所期望的那样。尝试
result
sa多一点,(在字典中读取do script
中有一个返回值);哦,如果您愿意假设h.terminal
将始终在不到一秒钟内成功打开,因此将是窗口1;我将您的脚本重新启动到以下:One helpful habit when programming is to keep an eye on what actually happens after you add any unfamiliar code. The quick way to do this in AppleScript is with the
result
variable. Commands' return values go toresult
, but you can also explicitly set it for clarity. The value inresult
is shown at the bottom of the default window in Script Editor.For example, I pasted in just this portion of your script, with a tweak:
Execution took waaay too long, and the
result
wasmissing value
. So right off the bat we know nothing else is going to work. But why?I chose "Open Dictionary…" from the "File" menu, and chose Terminal. It seems Terminal uses the
open
command from the Standard Suite, which means it by default wants an AppleScript path, not a POSIX path.Well, it opened instantly now, but even that doesn't help as
result
isn't right. It seems theopen
command does not return a reference to the new window, as I believe you were expecting.Experimenting with
result
s a bit more, (and reading in the dictionary that there is a return value fromdo script
); oh, and if you're willing to assume thath.terminal
will always open successfully in less than one second, and will therefore be window 1; I rejiggered your script to the following: