Python 为什么在Firefox中,在applescript、shell脚本、Perl和ruby中打开URL后不能使用参数?

Python 为什么在Firefox中,在applescript、shell脚本、Perl和ruby中打开URL后不能使用参数?,python,ruby,perl,applescript,firefox-addon-sdk,Python,Ruby,Perl,Applescript,Firefox Addon Sdk,使用Safari或Chrome,您可以使用参数打开URL Safari中Applescript中的示例 打开位置”https://translate.google.com/#auto/en/“&(剪贴板) Firefox的命令行允许打开url,但没有参数。 有没有办法通过脚本来避免这种失败 AppleScript示例: tell application "Safari" activate try open location "translate.google.co

使用Safari或Chrome,您可以使用参数打开URL

Safari中Applescript中的示例

打开位置”https://translate.google.com/#auto/en/“&(剪贴板)

Firefox的命令行允许打开url,但没有参数。 有没有办法通过脚本来避免这种失败

AppleScript示例:

tell application "Safari"
    activate
    try
        open location "translate.google.com/#auto/en/" & (the clipboard)
    end try
end tell

我不确定问题到底是什么——如果你能把它包括在内,那会有很大帮助

  • 确切地说,您正在做什么(在这种情况下,剪贴板中的内容至关重要)
  • 你期望发生什么
  • 到底发生了什么
  • 对于这个答案,我假设你的剪贴板中有一些非英语文本,你想用谷歌翻译把它翻译成英语。在这种情况下,只要剪贴板的内容采用正确的格式,您所拥有的内容就可以工作。例如,此脚本将打开一个Safari窗口,将法语翻译为英语:

    set the clipboard to "Où sont les neiges d'antan"
    
    tell application "Safari"
        activate
        try
            open location "translate.google.com/#auto/en/" & (the clipboard)
        end try
    end tell
    

    我真的不知道你出了什么问题,但有一种可能是剪贴板中的内容不是纯文本,而是某种格式化的文本(rtf、html或类似的东西),并且格式化会随文本一起出现。在这种情况下,使用
    (剪贴板作为文本)
    可能会解决这个问题。或者不是。我需要更多的信息来告诉你到底发生了什么。

    你说什么,既然你不理解这个问题,你可以假设一切。如果你不明白,不要强迫自己去发明答案。applescript中提供的脚本对于Safari非常有效。 问题很简单,为什么Firefox不能用参数url请求完成命令行。因此,使用Safari或Chrome的示例如下:

    *Open location "https://translate.google.com/#auto/en/" & (the clipboard)*
    
    这里的论点是剪贴板,当然我们之前已经用文本填充了要翻译的内容

    可能没有理由让它与Firefox一起工作。尤其要记住,我们谈论的是Firefox。applescript for Safari中的脚本非常有效

    **Tell application "Safari"
    activate
    try
    Open location "https://translate.google.com/#auto/en/" & (the clipboard)
    end try
    end tell**
    
    这是适用于Firefox的方法。这不是最快的,因为如果需要剪贴板的全部内容,必须首先格式化文本。我必须在Automator中创建服务,而无需输入,这样服务才能普遍适用于任何地方。

    在Firefox中,Safari或Chrome不存在的问题是,当我们调用“translate.google.com”并将剪贴板与之关联时,文本在到达时没有格式化,导致错误404。因此,如果你在两个步骤中进行操作,当然没有问题,打开页面“translate.google.com”菜单编辑并粘贴

    [![** 
    on run {input, parameters}
            tell application "System Events"
                keystroke "c" using command down
            end tell
        tell application "Applications/Firefox.app" to activate
        tell application "System Events" to tell process "Firefox"
            set frontmost to true
            set sentence to text of (the clipboard)
            set thesentences to paragraphs of sentence
            set thenewsentences to thesentences as string
            set the clipboard to thenewsentences
            keystroke "t" using command down
            keystroke "https://translate.google.com/#auto/fr/" & (the clipboard) & return
        end tell
        end run 
    

    **]]

    我不明白你的问题。请出示您的密码好吗?不管是AppleScript、Python、Perl、Ruby还是shell脚本,不管脚本语言是什么(AppleScript、pyton、Perl、Ruby),都能找到一种方法将参数(如Chrome或Safari)传递给Firefox。告诉应用程序“Safari”激活try Open location”“&(剪贴板)end try end Tell可能Firefox根本不知道如何处理这些参数?url的这部分称为“”,而不是“参数”。这个问题不应该关闭,它是一个编程问题。这不是答案,应该添加到问题中。