【问题标题】:Applescript quit after 1 minuteApplescript 1 分钟后退出
【发布时间】:2020-11-27 02:46:12
【问题描述】:

我在 xcode 中有一个非常简单的 applescript 应用程序,它只打开一个窗口并有一个重定向到网站的按钮。如果用户在 60 秒内没有点击按钮,有没有办法自动退出窗口。 这是我的代码

script AppDelegate
    -- property parent : class "NSObject"
    
    -- IBOutlets
    property theWindow : missing value
    
    on applicationWillFinishLaunching_(aNotification)
        -- Insert code here to initialize your application before any files are opened
    end applicationWillFinishLaunching_
    
    on buttonClicked_(sender)
        open location "https://example.com"
        quit
    end buttonClicked_
    
    on applicationShouldTerminate_(sender)
        -- Insert code here to do any housekeeping before your application quits 
        return current application's NSTerminateNow
    end applicationShouldTerminate_
    
end script

【问题讨论】:

  • 你可以通过使用带有超时的display dialog来避免整个Xcode的事情。
  • @red_menace 我不能,我还在窗口中插入图像,所以我必须使用 xcode。
  • 您也可以使用辅助视图,但是您是如何显示窗口的,或者界面编辑器中的所有内容?
  • @red_menace 我在 .xib 文件中创建了一个窗口,它有一个完整的 gui,您可以在其中拖动按钮和图像(我显然是个菜鸟)。我到处查找,但似乎无法找到如何做到这一点
  • @red_menace 我通过open compiled.app展示了这一点

标签: xcode macos popup applescript


【解决方案1】:

由于应用程序启动时会显示窗口,因此您可以在 applicationWillFinishLaunching 方法的延迟后调用方法/处理程序。由于您还退出了按钮处理程序,因此可以执行双重任务,例如,替换这些处理程序:

on applicationWillFinishLaunching_(aNotification)
    my performSelector:"buttonCLicked:" withObject:me afterDelay:60
end applicationWillFinishLaunching_

on buttonClicked_(sender)
    if sender is not me then open location "https://example.com"
    current application's NSApp's terminate:me -- quit
end buttonClicked_

【讨论】:

    猜你喜欢
    • 2023-03-12
    • 1970-01-01
    • 1970-01-01
    • 2014-08-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-16
    • 2018-02-21
    相关资源
    最近更新 更多