AppleScript在双引号之间将字符串插入应用程序

时间:2012-06-03 16:30:37

标签: applescript double-quotes

我刚刚为我的Mac购买了Alfred App,我想使用我在网上找到的这个脚本:

---------------------------------------------------
--Modified by: Pontus Sundén, http://psu.se
--Icon from: http://findicons.com/pack/1362/private_eye_act_1
---------------------------------------------------
on alfred_script(strQuery)
    --Get the parameters passed to the script - this is the search query
    set strSearchCriteria to SpaceList(strQuery)

    --Try to populated an existing window with the search query
    tell application "Evernote"
        try
            set query string of window 1 to strSearchCriteria
        on error
            --No existing window, open an new one
            open collection window with query string strSearchCriteria
        end try
    end tell
    tell application "System Events" to set frontmost of process "Evernote" to true
end alfred_script


--Take a list of text items and retrun them as a string with a space between each item
on SpaceList(astrItems)
    --Store what the current list delimiter is
    set tmpDelimiters to AppleScript's text item delimiters

    --Set the list delimiter to a space and build the string we want to pass back
    set AppleScript's text item delimiters to " "
    set strReturn to astrItems as string

    --Set the list delimiter back to what it was previously
    set AppleScript's text item delimiters to tmpDelimiters

    --Return the string we built
    return strReturn
end SpaceList

应该打开evernote并搜索某些内容。它工作正常,但不是搜索,比如说“船”这个词,它将用双引号搜索“船”,显然这不会产生匹配。

2 个答案:

答案 0 :(得分:0)

您可以使用UI脚本来填充搜索字段,如下所示:

set xxx to "boat"
activate application "Evernote"
tell application "System Events" to tell process "Evernote"
    set value of text field 1 of group 4 of tool bar 1 of window 1 to xxx
end tell

答案 1 :(得分:0)

您的脚本完全正确 - 通过AppleScript传递的搜索词的虚假引用是客户端版本3中的已知的Evernote错误(好吧,“已知”在“我打开支持票证中”不久之前,Evernote承认它“;我会添加一个链接到故障单,但这些是打开它的用户私有...但会更新进度,但是。”

在他们解决问题之前,您必须使用the suggested GUI Scripting solution作为解决方法,或者手动更正搜索字符串。