我有一些我正在执行的AppleScript代码osascript.这是更大的Perl程序的一部分.我希望能够从AppleScript打印到stdout,然后让Perl脚本处理输出.但是我无法在AppleScript中打印.我该怎么办?
这是我尝试过的:
do shell script "echo Foo".不是ouptut Foo.这是我正在运行的脚本:
tell application "Safari"
set window_list to every window
repeat with the_window in window_list
set tab_list to every tab in the_window
repeat with the_tab in tab_list
set the_url to the URL of the_tab
-- I'd like to put a print statement here,
-- instead of display dialog
display dialog the_url
end repeat
end repeat
end tell
Run Code Online (Sandbox Code Playgroud)
由于osascript将自动打印程序的最后一个值,我可以将URL收集到列表中并打印出来.但是我的Perl脚本必须解析列表,删除引号等.似乎每行只打印一个URL应该更直接.
谢谢
我不知道如何做你所要求的事情,而且我不了解 Perl,但是我认为如果你在字符串而不是列表中收集 url,你可以使 Perl 的解析变得简单。每个 url 将位于字符串的单独行上。Perl 应该能够很容易地将其转换为数组,然后用它做一些事情。像下面的苹果脚本一样。当然,您可以在 applescript 中使用不同的分隔符。我使用了“return”,但它也可以很容易地是“逗号”或您想要的任何其他字符。在 perl 中,将字符串更改为数组对您来说最简单的方法。
set urlString to ""
tell application "Safari"
set window_list to every window
repeat with the_window in window_list
set tab_list to every tab in the_window
repeat with the_tab in tab_list
set the_url to the URL of the_tab
set urlString to urlString & the_url & return
end repeat
end repeat
end tell
return text 1 thru -2 of urlString
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4511 次 |
| 最近记录: |