学习的AppleScript:无法连结到Safari [英] Learning Applescript: Trouble linking to Safari

查看:349
本文介绍了学习的AppleScript:无法连结到Safari的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

跑下来

您好,这是一个非常特殊的情况和问题。基本上,我在Safari上运行的AppleScript在Automator中,其结果是空。

Hello, this is a very specific and situation question. Basically, I'm running Applescript in Automator on Safari, and the result is Null.

我有什么

我现在有一个脚本,可以做这些事情:

I currently have a script that can do these things:


  1. 在我即使运行的Automator程序,我有Safari中打开

  1. Before I even run the Automator program, I have Safari open

接下来,我运行的Automator,与此code开头:

Next I run the Automator, which starts with this code:

on run {input, parameters}

    tell application "Safari" to activate
    tell application "System Events"
        keystroke "t" using command down
    end tell
    return input
end run

该脚本将启动Safari浏览器,并打开一个新的标签。

This script will activate Safari, and open a new tab.

接下来,我有一个Automator的停顿。这将使该页面时加载

Next I have an Automator pause. This will give the page time to load

Safari的网页打开后,我运行这个code:

After the Safari page has opened, I run this code:

on run
    clickID("75610556")
end run

on clickID(theId)
    tell application "Safari"
        do JavaScript "document.getElementById(‘" & theId & "‘).click();" in document 1
    end tell
end clickID

本脚本应该选定ID为75610556的按钮,但事实并非如此。这是我的计划的关键问题。

This script should of selected the button with the ID "75610556", but it did not. This is the key problem with my program.

接下来我运行下面的code:

Next I run the following code:

on run {input, parameters}

    tell application "Safari" to activate
    tell application "System Events"
        keystroke "w" using command down
    end tell

    return input
end run

这将关闭当前标签。

接下来,我遍历与Automator的循环。

Next, I loop through with an Automator loop.

我想帮助

我将解决我的问题的程序一步一步来。

I will address my questions for the program step by step.


  1. 有关的步骤之一,这是设置事情的好办法?是的Automator甚至去一个适当的方式?

  1. For step one, is this a good way to set things up? Is Automator even a proper way to go?

这是code高效?任何错误了吗?

Is this code efficient? Any errors yet?

我真的希望有来替代。我还没有找到一个。

I really hope there is an alternative to this. I have not found one.

为什么不这项工作在Safari?我觉得像我这样做的权利。

Why won't this work in Safari? I feel like I have done this right.

同2号,只是好奇,如果这是处理的最佳方式本

Same as number 2, just curious if this is the best way to handle this

我觉得这是做事情的好办法。

I think this is a good way to do things.

为什么我需要这个+每一个细节(可选部分)

这是额外的细节,如果你想他们。它会给你几乎每一个细节,并解释为什么我需要这个。

These are extra details if you want them. It will give you nearly every detail, and explain why I need this.

所以在我的大学商业较量。我是一个大一的程序员,并且已经设定了一个非常简单的移动网络游戏。问题是有奖金的敌人以投票网站$ 3,000。这个网站是投票无处不在。法官并没有意识到这网站没有丝毫保障。我们报道它,法官认为这是不够的理由取消投票,也许寻找新的替代不错。我们报道,民意调查到处可以操纵工作,任何团队优势谁是足够聪明的:

一个。关闭浏览器的Cookie

乙。使用私人浏览器

但当然,评委们不听。他们认为,如果有人彻夜未眠,这可能会改变,但在2-3个小时内,将收效甚微。为了阻止他们的裁决,我想作一个例子程序为他们在我的Mac,将打击他们的头脑:一个投票程序。这一计划将打开Safari。 Safari浏览器已经配置在私人浏览模式来打开投票页面。我所有的程序所要做​​的就是打开一个新的选项卡,找到按钮的ID,并点击它。越快做到这一点就更好了。


  • 最后一点:当时后面的故事太多了?我知道堆栈溢出有一个闲细节的政策。我以为精心制作的版本可能有帮助,但如果它是一件坏事,我会删除它。

推荐答案

不幸的是我没有太多的时间来回答你所有的问题,因为它是晚,我需要去睡觉,但这里是所有的例子你需要做的。无需Automator的,这似乎只是你的过程变得复杂了我。

Unfortunately I don't have a lot of time to answer all your questions as it's late and I need to get to bed, but here is an example of all you need to do. No need for automator, that just seems to complicate your process to me.

您可能需要调整一些睡眠设置一点点,如果你需要更多的等待的时候,我想这是我的本地Web服务器上,它的工作,但这是当地的使网站加载速度非常快。

You may want to tweak some of the sleep settings a little if you need more "wait" time, I tried this on my local web server and it worked, but it's local so the site loads very fast.

on run
    set i to 1
    repeat until i > 5
        do shell script "sleep 2"
        tell application "Safari"
            activate
            tell window 1
                set properties of current tab to {URL:"http://yoururl.com"}
            end tell

        end tell
        do shell script "sleep 3"

        tell application "Safari"
            tell document 1
                do JavaScript "document.getElementById(\"75610556\").click();"
            end tell
            quit
        end tell
        set i to i + 1
    end repeat
end run

另外请注意,你需要将URL更改为您的网址它说: http://yoururl.com ,你可能会想更改重复,直到我> 5 来大量让它重复以上。

Also note, you'll need to change the url to your url where it says "http://yoururl.com" and you'll probably want to change the 5 in repeat until i > 5 to a larger number to let it repeat more.

这篇关于学习的AppleScript:无法连结到Safari的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆