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

Why with Firefox you can not use arguments after opening a URL in applescript, shell script , Perl, ruby?

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

Safari 中的 Applescript 示例

Open location "https://translate.google.com/#auto/en/" & (the clipboard)

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

AppleScript 示例:

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

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

  1. 你在做什么(在这种情况下,剪贴板中的内容很重要)
  2. 你期望发生什么
  3. 实际发生了什么

对于这个答案,我假设您的剪贴板中有某种非英语文本,并且您想使用 Google translate 将其翻译成英语。在这种情况下,只要剪贴板的内容格式正确,您所拥有的就应该可以工作。例如,此脚本将打开 Safari window 将法语翻译成英语:

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 或类似的东西), 并且格式与文本一起包含在内。在这种情况下,使用 (the clipboard as text) 可能会解决问题。或不。我需要更多信息来了解实际情况。

你说呢,既然你看不懂问题,那你就随便猜吧。如果你不明白,不要强迫自己编造答案。 applescript 中提供的脚本非常适用于 Safari。 问题很简单,为什么使用 Firefox 无法完成带有参数 url 请求的命令行。因此,适用于 Safari 或 Chrome:

的示例
*Open location "https://translate.google.com/#auto/en/" & (the clipboard)*

这里的参数是剪贴板,当然我们之前已经填满了要翻译的文本。

它可能无法与 Firefox 一起使用。特别要记住我们正在谈论 Firefox。 Safari 的 applescript 脚本有效

**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 

**]1]1