我正在从事一个项目,该项目涉及使用Applescript在用户Google Chrome浏览器中列出打开的URL,以便在我最终要重新打开Chrome时保存它们。发现我需要一种方法来确定哪个窗口中存在哪些选项卡,所以我决定尝试在Applescript中创建一个嵌套列表,其中每个窗口都是其自身的选项卡URL子列表,然后在声明的变量中返回它在子外壳之前。
我这样做的方法是通过以下代码
tabs=$(/usr/bin/osascript << EOT
tell application "Google Chrome"
# save a variable to the number of windows open
set windowCount to number of windows
set myWindows to {}
repeat with x from 1 to windowCount
# count the tabs in the window we are iterated upon
set tabcount to number of tabs in window x
# this list will hold the URLs,delimited by commas
set myURLs to {}
# secondary loop,this time iterating tabs
repeat with y from 1 to tabcount
# grab URL from current tab
set tabURL to URL of tab y of window x
# append URL to end of list
copy tabURL to the end of myURLs
end repeat
# this means our end result will be a list of lists
# containing the URLs of all the tabs of all the windows
copy myURLs to the end of myWindows
end repeat
return myWindows
end tell
EOT)
我遇到的问题是,尽管Applescript正在正确构建嵌套列表,即
{{"https://stackoverflow.com/questions/ask"},{"https://twitter.com","https://facebook.com"}}
当我稍后引用$tabs
时,Bash似乎使列表变平了
https://stackoverflow.com/questions/ask,https://twitter.com,https://facebook.com
这使我相信在传递复杂变量时Applescript和Bash不会相处。是这种情况,并且Bash无法从Applescript读取多维列表吗?还是我只是对此编程不正确?
谢谢!