我正在使用 BetterTouchTool 自定义 MacBook Pro 上的触摸栏。到目前为止,我已经使用下面的脚本来显示在 Chrome 中打开的选项卡列表。我想在页面名称旁边显示网站图标。
if application "Google Chrome" is running then
tell application "Google Chrome"
try
set windowCount to number of windows
repeat with x from 1 to windowCount
set maxSize to 15
set tabcount to number of tabs in window x
repeat with y from 1 to tabcount
set tabName to title of tab 1 of window x
if length of tabName is greater than maxSize then
set tabName to text 1 thru (maxSize - 3) of tabName & "..."
end if
return tabName
end repeat
end repeat
on error
return ""
end try
end tell
else
return ""
end if
编辑1(答案后的新脚本)
if application "Google Chrome" is running then
tell application "Google Chrome"
set windowCount to number of windows
repeat with x from 1 to windowCount
set maxSize to 15
set tabcount to number of tabs in window x
repeat with y from 1 to tabcount
set tabName to title of tab 1 of window x
if length of tabName is greater than maxSize then
set tabName to text 1 thru (maxSize - 3) of tabName & "..."
end if
set tabIcon to execute of tab 1 of window x javascript ¬
"document.head.querySelector('link[rel~=icon]').href;"
return "{\"text\":\"" & (tabName) & "\",
\"icon_data\": \"base64_icon_data\",
\"icon_path\":\"" & (tabIcon) & "\",
\"background_color\": \"255,85,100,255\",
\"font_color\": \"100,200,100,255\",
\"font_size\": 10}"
end repeat
end repeat
end tell
else
return ""
end if
由于我是 Applescript 的新手,因此我可能遗漏了一些非常明显的东西。