freedomSky
2015-09-07 11:19:03 +08:00
实现过搜索 Chrome 书签的,要用到 AppleScript ,不知道现在能用 JavaScript 不能
就是调用 Chrome 的接口遍历一下书签文件夹,最终将符合条件的内容按 Alfred 的要求输出一下
下边是一部分 AppleScript ,参考一下吧:)
global rstXML
on run argv
set hdl to load script POSIX file (POSIX path of ((path to me as text ) & "::") & "handler.scpt")
global allBookmarks
set queryStr to argv as string
set allBookmarks to {}
set rstXML to "<?xml version=\"1.0\"?><items>"
tell application "Google Chrome"
set folders to (every bookmark folder of application "Google Chrome")
repeat with folder in folders
set f to folder
hdl's dealFolder (f, allBookmarks, queryStr )
end repeat
set rstXML to rstXML & "</items>"
return rstXML
end tell
end run
on dealItem (itm, allBookmarks, queryStr )
tell application "Google Chrome"
set t to (title of itm ) as string
set t to my q_encode (t )
set u to (URL of itm ) as string
set u to my q_encode (u )
set end of allBookmarks to {ptitle:t, purl:u}
# if t contains queryStr then
set rstXML to rstXML & "<item uid=\"" & u & "\" arg=\"" & u & "\" valid=\"YES\" type=\"file\">
<title>" & t & "</title>
<subtitle>" & u & "</subtitle>
<icon>flickr.png</icon>
</item>"
# end if
end tell
end dealItem
on dealFolder (curFld, allBookmarks, queryStr )
tell application "Google Chrome"
tell curFld
set itms to (every bookmark item )
repeat with itm in itms
my dealItem (itm, allBookmarks, queryStr )
end repeat
set flds to (every bookmark folder )
repeat with fld in flds
my dealFolder (fld, allBookmarks, queryStr )
end repeat
end tell
end tell
end dealFolder