2011-02-06 47 views
0

我正在嘗試編寫Apptivate的AppleScript以在Google Chrome中打開當前的Firefox 4或Safari選項卡。 Safari部分工作,if語句步入Firefox,但不復制URL。AppleScript在Google Chrome中打開當前的Firefox 4選項卡

這是我的AppleScript,它不工作:

tell application "System Events" 
set myApp to name of first application process whose frontmost is true 
if myApp is "firefox-bin" then 
    tell application "Firefox" to set theURL to the «class curl» of frontmost of window 1 
    tell application "Google Chrome" 
     activate 
     tell application "System Events" to keystroke "t" using {command down} 
     set URL of last tab of window 1 to theURL 
    end tell 
else if myApp is "Safari" then 
    tell application "Safari" to set theURL to the URL in document 1 
    tell application "Google Chrome" 
     activate 
     tell application "System Events" to keystroke "t" using {command down} 
     set URL of last tab of window 1 to theURL 
    end tell 
end if 
end tell 

我缺少什麼?

回答

1

這可能會很棘手,但您可以使用鍵盤快捷鍵在Chrome中複製並打開您需要的網址。檢查代碼:

set backupClipboard to the clipboard 

on ApplicationIsRunning(appName) 
    tell application "System Events" to set appNameIsRunning to exists (processes where name is appName) 
    return appNameIsRunning 
end ApplicationIsRunning 

on copyURL(appName) 
    tell application appName to activate 
    tell application "System Events" 
     keystroke "lc" using command down 
    end tell 
    delay 0.2 -- to make sure keystroke will hit cmd+l & cmd+c 
end copyURL 

if ApplicationIsRunning("firefox-bin") then 
    copyURL("Firefox") 
else if ApplicationIsRunning("Safari") then 
    copyURL("Safari") 
else 
    return 
end if 

tell application "Google Chrome" 
    open location (the clipboard) 
    activate 
end tell 

set the clipboard to backupClipboard 

這個腳本會先保存當前剪貼板,然後它會檢查該瀏覽器打開。您可以通過對if語句進行排序來定義瀏覽器的優先級。

這與在瀏覽器中按cmd + L(選擇url)和cmd + C(複製)相同。

此外,您可以調整代碼以支持其他瀏覽器。

(從ApplicationIsRunning功能:http://vgable.com/blog/2009/04/24/how-to-check-if-an-application-is-running-with-applescript/

0

我在PPC上運行OS 10.4.11,我似乎找到了與喜歡的東西「富標籤」的腳本問題。我認爲問題是我有這樣一箇舊設備,腳本不會識別這些較新的命令。也許這是我。

無論如何,我希望能夠通過運行magicmouse.jp驅動程序,使用我的Magic Mouse觸發一個從Firefox到Safari的副本。我用它來工作如下:

tell application "Firefox" to activate 

tell application "System Events" 

keystroke "lc" using command down 

end tell 



tell application "Safari" to activate 

delay 1 

tell application "System Events" to keystroke "l" using {command down} 

--delay 0.2 

tell application "System Events" to keystroke "v" using {command down} 

tell application "System Events" to keystroke return 

##############

歡呼。

P.S.作爲一個側面說明,一些研究表明,一些人在Safari中禁用了Flash,然後觸發了一個在Chrome中打開的複製URL,這顯然必須是一個更安全的容器,因爲它是值得的。

相關問題