0

我正在使用下面的代码在applescript中使用google查询打开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
4

1 回答 1

1

尝试这个:

tell application "Firefox"
    open location newurl
end tell

编辑:

Firefox 不会自动激活,所以我试了一下:

tell application "Firefox"
    activate
    open location "http://www.wikipedia.com/"
end tell

在这里工作。

这里更多关于编码文本: http: //www.macosxautomation.com/applescript/sbrt/sbrt-08.html

EDIT2:好的,我明白你的意思,可以这样解决:

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
于 2013-10-13T16:45:26.143 回答