我有一些正在执行的 AppleScript 代码osascript
。这是一个更大的 Perl 程序的一部分。我希望能够从 AppleScript 打印到标准输出,然后让 Perl 脚本处理输出。但我无法从 AppleScript 中进行打印。我应该怎么办?
这是我尝试过的:
-
do shell script "echo Foo"
。不输出 Foo。
-
此 Google 网上论坛讨论 http://groups.google.com/group/alt.comp.lang.applescript/browse_thread/thread/d6fd2cd13927d5b3/5cba6813346a1750使用一些技巧来打开/dev/fd/1。对我来说,我收到错误“未找到文件 Macintosh HD:dev:fd:1”
这是我正在运行的脚本:
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
Since osascript
会自动打印程序的最后一个值,我可以将 URL 收集到列表中并打印它。但是我的 Perl 脚本必须解析列表、删除引号等。似乎每行只打印一个 URL 应该更简单。
Thanks
我不知道如何做你所要求的事情,而且我不了解 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
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)