2011-02-06 48 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,这显然必须是一个更安全的容器,因为它是值得的。

相关问题