2013-10-13 1 views
0

나는 새로운 구글이 유튜브에 내 검색 문자열을 가지고 다니지 않아서 애플 스크립트에서 구글 쿼리로 유튜브를 열려면 아래 코드를 사용하고 있습니다 .Unable에서 구글 검색 문자열로 firefix에서 URL을 열려면 파이어 폭스. 나는 정말로 도움을 주셔서 감사합니다. 미리 감사드립니다.유튜브에서 구글 검색 쿼리를 열려면 applescript

여기에 오류가 점점 오전 :

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 

답변

1

이 시도 :

tell application "Firefox" 
    open location newurl 
end tell 

편집 :

파이어 폭스가 자동으로 활성화하지 않는, 그래서 난 그냥이 시도

:

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

w hich는 여기에서 일한다. http://www.macosxautomation.com/applescript/sbrt/sbrt-08.html

EDIT2 : OK, 난 당신이 무슨 뜻인지보고, 그 다음과 같이 해결 될 것입니다 : 여기에 더 인코딩 텍스트에 대한

나는 또한하지만 아무것도하지 않는 것을 시도

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 
+0

! 코드에 오류가 없습니다. 그러나 새 창 (탭이 열리지 않음). – jason

+0

하드 코드 된 URL로 시도해보십시오. 작동하는 경우 URL (이 경우 "nameOnly12"의 내용)을 인코딩해야합니다. - 최신 Firefox를 사용하여 OS 10.8.2에서 다시 시도했으며 유효한 위치 인 –

+0

을 열어 newurl을 글로벌로 만들었습니다. newurl을 글로벌하게 만들지 않고 다른 방법으로 말해 줄 수 있습니까 ?? – jason