applescript在youtube中打开google搜索查询

applescript在youtube中打开google搜索查询,applescript,Applescript,我正在使用下面的代码在applescript中使用google query打开youtube,因为新的google没有将我的搜索字符串带到youtube。无法在firefox中使用google搜索字符串在firefix中打开url。我真的很感谢你的帮助。提前谢谢你 我在这里得到一个错误: tell application "Firefox" to activate tell application "System Events" keystroke "l" using command d

我正在使用下面的代码在applescript中使用google query打开youtube,因为新的google没有将我的搜索字符串带到youtube。无法在firefox中使用google搜索字符串在firefix中打开url。我真的很感谢你的帮助。提前谢谢你

我在这里得到一个错误:

tell application "Firefox" to activate
tell application "System Events"
    keystroke "l" using command down
    keystroke "c" using command down

    set tr to get the clipboard


end tell



return trimgoogle(tr)
on trimgoogle(sourceAddress)
    set AppleScript's text item delimiters to {"#"}
    set addressParts to (every text item in sourceAddress) as list
    set AppleScript's text item delimiters to ""
    set nameOnly to item 2 of addressParts

    set AppleScript's text item delimiters to {"&"}
    set addressParts2 to (every text item in nameOnly) as list
    set AppleScript's text item delimiters to ""
    set nameOnly1 to item 1 of addressParts2
    set nameOnly2 to nameOnly1


    set AppleScript's text item delimiters to {"="}
    set addressParts21 to (every text item in nameOnly2) as list
    set AppleScript's text item delimiters to ""
    set nameOnly12 to item 2 of addressParts21


    set newurl to "http://www.youtube.com/results?search_query=" & nameOnly12

    return newurl

end trimgoogle

tell application "Firefox"
OpenURL  newurl
end tell
试试这个:

tell application "Firefox"
    open location newurl
end tell
编辑:

Firefox不会自动激活,所以我尝试了以下方法:

tell application "Firefox"
    activate
    open location "http://www.wikipedia.com/"
end tell
这在这里起作用

以下是有关编码文本的详细信息:

编辑2: 好吧,我明白你的意思了,可以这样解决:

tell application "Firefox" to activate
tell application "System Events"
    keystroke "l" using command down
    keystroke "c" using command down
    set tr to get the clipboard
end tell

set newurl to my trimgoogle(tr)

tell application "Firefox"
    activate
    open location newurl
end tell

on trimgoogle(sourceAddress)
    set AppleScript's text item delimiters to {"#"}
    set addressParts to (every text item in sourceAddress) as list
    set AppleScript's text item delimiters to ""
    set nameOnly to item 2 of addressParts

    set AppleScript's text item delimiters to {"&"}
    set addressParts2 to (every text item in nameOnly) as list
    set AppleScript's text item delimiters to ""
    set nameOnly1 to item 1 of addressParts2
    set nameOnly2 to nameOnly1

    set AppleScript's text item delimiters to {"="}
    set addressParts21 to (every text item in nameOnly2) as list
    set AppleScript's text item delimiters to ""
    set nameOnly12 to item 2 of addressParts21

    set newurl to "http://www.youtube.com/results?search_query=" & nameOnly12

    return newurl

end trimgoogle

我也试过了,但没用!!代码中没有错误。但新窗口(选项卡未打开)。请使用硬编码的url进行尝试。如果它能工作,你必须对你的url进行编码(在本例中,是“仅限名称12”的内容)-我刚刚在OS 10.8.2上用最新的Firefox再次尝试了它,它打开了一个有效的位置,使newurl全局化,并开始工作。你能告诉我没有使newurl全局化的其他方法吗?只是想澄清一下:Firefox没有名为“OpenURL”的命令但是“开放的位置”http://...“看起来很有效。非常感谢。这是一个很大的帮助:)