You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何用AppleScript实现Arc浏览器带参数自动打开窗口(仿Safari)

Arc浏览器Launchbar有声书搜索脚本适配方案

问题分析

原脚本中Safari可正常通过动态拼接的URL打开搜索标签,但Arc浏览器仅支持固定URL,动态拼接的URL会报错——核心原因是未对搜索关键词进行URL编码,含空格、特殊字符的关键词会破坏URL格式,而Arc的AppleScript接口对URL格式的校验比Safari更严格。

适配后的完整脚本

on handle_string(_string)
    -- 对搜索关键词进行URL编码,避免特殊字符破坏URL结构
    set encodedString to do shell script "python3 -c 'import urllib.parse; print(urllib.parse.quote(\"" & _string & "\"))'"
    
    -- 拼接编码后的搜索URL
    set SFLibrarySearch to "https://sfpl.bibliocommons.com/search?custom_query=anywhere%3A(" & encodedString & ")+++language%3A%22eng%22+formatcode%3A(BOOK_CD+OR+AB+)&suppress=true&custom_edit=false"
    set AudiblecomLibrarySearch to "http://www.audible.com/search/ref=a_hp_tseft?advsearchKeywords=" & encodedString & "&field_language=9178177011&ref_=a_search_l2_2_1_srchBin&selectedNodeId=9178176011&qid=1468117332&searchSize=20&sr=1-1"
    
    -- Safari部分保留原逻辑
    tell application "Safari"
        open location SFLibrarySearch
        open location AudiblecomLibrarySearch
        activate
    end tell
    
    -- Arc浏览器适配逻辑
    tell application "Arc"
        -- 确保前置窗口存在,无窗口则新建
        if not (exists front window) then
            make new window
        end if
        tell front window
            tell space "General"
                -- 依次创建搜索标签
                make new tab with properties {URL:SFLibrarySearch}
                make new tab with properties {URL:AudiblecomLibrarySearch}
            end tell
        end tell
        activate
    end tell
end handle_string

关键修改点

  • URL编码处理:通过Python的urllib.parse.quote对输入关键词编码,保证空格、特殊字符不会破坏URL结构,这是Arc能识别动态URL的核心前提
  • 窗口存在性检查:添加Arc窗口的存在性判断,避免因无前置窗口导致报错
  • 保留原有功能:维持Safari的搜索逻辑,同时让Arc在指定的"General"空间下创建搜索标签

内容的提问来源于stack exchange,提问作者Kohl Gill

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.08 11:08:17