修改AppleScript实现Skim.app全文搜索并在左侧面板展示结果
修改Skim的AppleScript实现全文搜索并在左侧面板展示结果
问题描述
我尝试通过Alfred打开Skim应用并搜索特定短语,使用的AppleScript代码如下:
on run argv set theQuery to item 1 of argv tell application "Skim" activate open "/Users/username/Dropbox/xys.pdf" set foundText to find front document text theQuery select foundText with animation end tell end run
当前代码可找到并高亮单个匹配实例,但我希望实现全文搜索,找到所有匹配实例并在左侧面板展示结果,请问如何修改该AppleScript代码?
解决方案
修改后的代码如下:
on run argv set theQuery to item 1 of argv tell application "Skim" activate -- 打开目标PDF并赋值给变量,明确操作对象 set targetDoc to open "/Users/username/Dropbox/xys.pdf" -- 使用Skim内置搜索命令,生成所有匹配结果并触发左侧面板展示 search targetDoc for theQuery -- 强制展开左侧的高亮/搜索结果面板 set show highlights pane of targetDoc to true end tell end run
关键修改说明
- 替换
find命令为search... for:该命令会调用Skim原生的全文搜索功能,自动在左侧面板生成所有匹配项的列表,而非仅定位单个结果 - 添加
set show highlights pane of targetDoc to true:确保左侧的搜索结果面板处于展开状态,直接展示所有匹配内容 - 使用变量
targetDoc指代打开的文档:让代码逻辑更清晰,避免依赖front document的上下文变化
内容的提问来源于stack exchange,提问作者Deon O'Brien
相关产品推荐
相关产品推荐

