使用swift关闭其他应用程序 [英] Close other applications using swift

查看:243
本文介绍了使用swift关闭其他应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法迅速关闭正在运行的应用程序?例如,如果我创建的应用程序需要关闭野生动物园.

Is there a way to close running applications in swift? For instance, if the application I create needs to close safari.

推荐答案

通过IF直接通过applescript当然可以实现:

It is certainly possible via an applescript directly IF:

您的应用未运行沙盒(请注意,如果您打算通过App Store分发它,则您的应用将被沙盒)

您的应用具有使用applescript的必要权利:com.apple.security.scripting-targets(苹果需要批准,并且您需要知道要定位的应用.这不是总括的许可)

your app is not running sandboxed (note that if you plan to distribute it via the App Store, your app will be sandboxed)
OR
your app has the necessary entitlements to use applescript: com.apple.security.scripting-targets (apple needs to approve that AND you need to know which apps to target. this isn't a blanket permission)

然后

  • https://apple.stackexchange.com/questions/60401/how-do-i-create-an-applescript-that-will-quit-an-application-at-a-specific-time
  • Can you execute an Applescript script from a Swift Application

如果您仍然不希望获得App Store的同谋,则也可以直接使用NSTask 脚本/代码段:

if you aren't going for App Store complicity anyways, you might also use NSTask directly scripts / code snippets:

  • How to force kill another application in cocoa Mac OS X 10.5
  • Can you execute an Applescript script from a Swift Application

短&甜:从技术上讲是,从政治上"也许是:D

short & sweet: technically yes, 'politically' maybe :D

这篇关于使用swift关闭其他应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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