Applescript 在 1 分钟后退出
Applescript quit after 1 minute
我在 xcode 中有一个非常简单的 applescript 应用程序,它只打开一个 window 并有一个重定向到网站的按钮。如果用户在 60 秒内没有单击按钮,有没有办法自动退出 window。
这是我的代码
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
由于 window 在应用程序启动时显示,您可以在 applicationWillFinishLaunching
方法延迟后调用 method/handler。由于您还退出了按钮处理程序,因此可以执行双重任务,例如,替换这些处理程序:
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_
我在 xcode 中有一个非常简单的 applescript 应用程序,它只打开一个 window 并有一个重定向到网站的按钮。如果用户在 60 秒内没有单击按钮,有没有办法自动退出 window。 这是我的代码
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
由于 window 在应用程序启动时显示,您可以在 applicationWillFinishLaunching
方法延迟后调用 method/handler。由于您还退出了按钮处理程序,因此可以执行双重任务,例如,替换这些处理程序:
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_