Vuo 2.4.4
Loading...
Searching...
No Matches
VuoAppLaunch.m
Go to the documentation of this file.
1
10#include "VuoAppLaunch.h"
11
13#include <AppKit/AppKit.h>
14
15#include "VuoUrl.h"
16
17#ifdef VUO_COMPILER
19 "title" : "VuoAppLaunch",
20 "dependencies" : [
21 "VuoUrl",
22 "AppKit.framework"
23 ]
24 });
25#endif
26
30void VuoAppLaunch_launch(VuoText rawUrl, bool activate)
31{
32 if (VuoText_isEmpty(rawUrl))
33 return;
34
36 NSString *urlAsString = [[NSString alloc] initWithUTF8String:normalizedUrl];
37 NSURL *url = [[NSURL alloc] initWithString:urlAsString];
38 [urlAsString release];
39
40 NSError *error = nil;
41#pragma clang diagnostic push
42#pragma clang diagnostic ignored "-Wdeprecated-declarations"
43 // The replacement, `-[NSWorkspace openApplicationAtURL]`, isn't available until macOS 11.
44 NSRunningApplication *app = [[NSWorkspace sharedWorkspace] launchApplicationAtURL:url
45 options:(activate ? 0 : NSWorkspaceLaunchWithoutActivation)
46 configuration:@{}
47 error:&error];
48#pragma clang diagnostic pop
49 if (! app)
50 VUserLog("Couldn't launch '%s': %s — %s", normalizedUrl,
51 [[error localizedDescription] UTF8String],
52 [[[[error userInfo] objectForKey:NSUnderlyingErrorKey] localizedDescription] UTF8String]);
53
54 VuoRetain(normalizedUrl);
55 VuoRelease(normalizedUrl);
56 [url release];
57}