File tree 6 files changed +48
-2
lines changed
6 files changed +48
-2
lines changed Original file line number Diff line number Diff line change 1
1
#include < iostream>
2
2
#include < pqrs/osx/workspace.hpp>
3
+ #include < unistd.h>
3
4
4
5
int main (void ) {
5
6
std::cout << " Finder: "
@@ -14,5 +15,11 @@ int main(void) {
14
15
std::cout << " NotFound: "
15
16
<< pqrs::osx::workspace::find_application_url_by_bundle_identifier (" org.pqrs.NotFound" ) << std::endl;
16
17
18
+ pqrs::osx::workspace::open_application_by_bundle_identifier (" com.apple.Safari" );
19
+ pqrs::osx::workspace::open_application_by_file_path (" /System/Applications/Utilities/Activity Monitor.app" );
20
+
21
+ // Wait open_application_*
22
+ sleep (1 );
23
+
17
24
return 0 ;
18
25
}
Original file line number Diff line number Diff line change 4
4
example :
5
5
type : tool
6
6
platform : macOS
7
- deploymentTarget : " 11 .0"
7
+ deploymentTarget : " 13 .0"
8
8
sources :
9
9
- path : main.cpp
10
10
compilerFlags :
Original file line number Diff line number Diff line change @@ -13,6 +13,14 @@ namespace pqrs {
13
13
namespace osx {
14
14
namespace workspace {
15
15
16
+ inline void open_application_by_bundle_identifier (const std::string& bundle_identifier) {
17
+ pqrs_osx_workspace_open_application_by_bundle_identifier (bundle_identifier.c_str ());
18
+ }
19
+
20
+ inline void open_application_by_file_path (const std::string& file_path) {
21
+ pqrs_osx_workspace_open_application_by_file_path (file_path.c_str ());
22
+ }
23
+
16
24
inline std::string find_application_url_by_bundle_identifier (const std::string& bundle_identifier) {
17
25
char buffer[512 ];
18
26
Original file line number Diff line number Diff line change @@ -10,6 +10,10 @@ extern "C" {
10
10
11
11
// Do not use these functions directly.
12
12
13
+ void pqrs_osx_workspace_open_application_by_bundle_identifier (const char * bundle_identifier );
14
+
15
+ void pqrs_osx_workspace_open_application_by_file_path (const char * file_path );
16
+
13
17
void pqrs_osx_workspace_find_application_url_by_bundle_identifier (const char * bundle_identifier ,
14
18
char * buffer ,
15
19
int buffer_size );
Original file line number Diff line number Diff line change 4
4
5
5
import AppKit
6
6
7
+ @_cdecl ( " pqrs_osx_workspace_open_application_by_bundle_identifier " )
8
+ func pqrs_osx_workspace_open_application_by_bundle_identifier(
9
+ _ bundleIdentifierPtr: UnsafePointer < Int8 >
10
+ ) {
11
+ let bundleIdentifier = String ( cString: bundleIdentifierPtr)
12
+
13
+ if let url = NSWorkspace . shared. urlForApplication ( withBundleIdentifier: bundleIdentifier) {
14
+ NSWorkspace . shared. openApplication (
15
+ at: url,
16
+ configuration: NSWorkspace . OpenConfiguration ( ) ,
17
+ completionHandler: nil
18
+ )
19
+ }
20
+ }
21
+
22
+ @_cdecl ( " pqrs_osx_workspace_open_application_by_file_path " )
23
+ func pqrs_osx_workspace_open_application_by_file_path( _ filePathPtr: UnsafePointer < Int8 > ) {
24
+ let filePath = String ( cString: filePathPtr)
25
+
26
+ let url = URL ( filePath: filePath, directoryHint: . notDirectory, relativeTo: nil )
27
+ NSWorkspace . shared. openApplication (
28
+ at: url,
29
+ configuration: NSWorkspace . OpenConfiguration ( ) ,
30
+ completionHandler: nil
31
+ )
32
+ }
33
+
7
34
@_cdecl ( " pqrs_osx_workspace_find_application_url_by_bundle_identifier " )
8
35
func pqrs_osx_workspace_find_application_url_by_bundle_identifier(
9
36
_ bundleIdentifierPtr: UnsafePointer < Int8 > ,
Original file line number Diff line number Diff line change 4
4
test :
5
5
type : tool
6
6
platform : macOS
7
- deploymentTarget : " 11 .0"
7
+ deploymentTarget : " 13 .0"
8
8
sources :
9
9
- path : test.cpp
10
10
compilerFlags :
You can’t perform that action at this time.
0 commit comments