如何通过 swift 以编程方式使用系统功能?
How to use system functionality programmatically via swift?
如果我们查看 machotkeys/shortcuts 的OS,我们会发现那里有很多功能。有些功能分配给了热键,有些则没有。
As example:
make screenshot(cmd+shif+F5)
or to show desktop (hide all apps) (F11)
和许多其他内置到 OS 函数中:
问题如下:如何在不使用热键模拟的情况下从我的代码中使用此功能?
目标是不要编写自定义代码,以防 OS 中已经存在此类功能。
我只找到了如何打开某种系统偏好设置,也许这是我需要去的方向,但我没有通过 google.
找到任何细节
import Cocoa
// Open Siri prefs
NSWorkspace.shared.open(URL(fileURLWithPath: "/System/Library/PreferencePanes/Speech.prefPane"))
// Open Siri prefs with another way
NSWorkspace.shared.open(URL(fileURLWithPath: "x-apple.systempreferences:com.apple.preference.speech"))
// Open System Preferences window
NSWorkspace.shared.open(URL(fileURLWithPath: "x-apple.systempreferences:com.apple.preference"))
您正在查看的区域是系统服务,实际上您的问题没有一个答案,因为其中一些项目可以通过自己的API获得,其中一些是私有的 macOS 功能,一些它们可通过实际服务获得。
您可以从以下方面开始您的发现:
BOOL NSPerformService(NSString *serviceItem, NSPasteboard *pboard)
以及 Services Implementation Guide,其中描述了详细信息。
使用这些东西的另一种机制是 AppleScript...非常广泛。
如果我们查看 machotkeys/shortcuts 的OS,我们会发现那里有很多功能。有些功能分配给了热键,有些则没有。
As example:
make screenshot(cmd+shif+F5)
or to show desktop (hide all apps) (F11)
和许多其他内置到 OS 函数中:
问题如下:如何在不使用热键模拟的情况下从我的代码中使用此功能?
目标是不要编写自定义代码,以防 OS 中已经存在此类功能。
我只找到了如何打开某种系统偏好设置,也许这是我需要去的方向,但我没有通过 google.
找到任何细节import Cocoa
// Open Siri prefs
NSWorkspace.shared.open(URL(fileURLWithPath: "/System/Library/PreferencePanes/Speech.prefPane"))
// Open Siri prefs with another way
NSWorkspace.shared.open(URL(fileURLWithPath: "x-apple.systempreferences:com.apple.preference.speech"))
// Open System Preferences window
NSWorkspace.shared.open(URL(fileURLWithPath: "x-apple.systempreferences:com.apple.preference"))
您正在查看的区域是系统服务,实际上您的问题没有一个答案,因为其中一些项目可以通过自己的API获得,其中一些是私有的 macOS 功能,一些它们可通过实际服务获得。
您可以从以下方面开始您的发现:
BOOL NSPerformService(NSString *serviceItem, NSPasteboard *pboard)
以及 Services Implementation Guide,其中描述了详细信息。
使用这些东西的另一种机制是 AppleScript...非常广泛。