【问题标题】:Need Applescript to repeat every x number of seconds需要 Applescript 每隔 x 秒重复一次
【发布时间】:2012-09-18 18:31:08
【问题描述】:

到目前为止,这是我的脚本:

property timeDelay : 5

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

if appOpen("iChat") then
    tell application "iChat"
        repeat with theService in services
            if connection status of theService = disconnected or connection status of theService = disconnecting then
                log in of service (name of theService)
            end if
        end repeat
    end tell
end if

基本上,如果您的任何 iChat/Messages 帐户已注销,它会检查一次。如果是,请登录。它可以工作。

不过,我希望这是一款“保持开放”的应用。过去我使用过该模式

on idle
    -- do stuff
end idle

..但由于某种原因,当我尝试编译时出错。

知道为什么会这样吗?

编辑:

好的——仍然不确定为什么会发生这种情况,但我可以通过简单地制作一个新脚本来解决这个问题。我不知道为什么会出现这个错误,但现在看起来很好。谢谢大家的帮助。

【问题讨论】:

  • 你应该用退货来代替你的延迟。

标签: osx-lion applescript


【解决方案1】:

这没有意义……

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

你想要这个...

tell application "System Events" to set appNameIsRunning to exists process appName

原因是“名称为 appName 的进程”将返回一个列表(无论它有一个项目还是多个它仍然是一个列表)并且检查列表的“存在”是没有意义的。

我不确定这个错误,但我希望能解决您的问题。

【讨论】:

  • 谢谢。它没有解决我的问题,但您的更改已被记录,我更新了我的脚本。
【解决方案2】:

这在 10.6.8 上适用于我

property timeDelay : 5

on appOpen(appName)
    tell application "System Events" to set appNameIsRunning to exists process appName
    return appNameIsRunning
end appOpen

on idle
    if appOpen("iChat") then
        tell application "iChat"
            repeat with theService in services
                if connection status of theService = disconnected or connection status of theService = disconnecting then
                    tell service (name of theService) to log in
                end if
            end repeat
        end tell
    end if
    return timeDelay
end idle

【讨论】:

    猜你喜欢
    • 2021-04-22
    • 2010-10-07
    • 1970-01-01
    • 2015-10-12
    • 2020-02-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多