- (void)openWithEditor:(NSString *)path atLine:(NSInteger)line {
NSWorkspace *sws = NSWorkspace.sharedWorkspace;
// construct BBEdit URL
NSString *encodedPath = [path stringByAddingPercentEncodingWithAllowedCharacters:NSCharacterSet.URLPathAllowedCharacterSet];
NSString *uri = [@"x-bbedit://open?url=file://" stringByAppendingString:encodedPath];
if (line != NSNotFound) {
uri = [uri stringByAppendingFormat:@"&line=%li", line];
}
NSURL *bbedit = [NSURL URLWithString:uri];
if ([sws openURL:bbedit]) {
my_os_log_debug("Using BBEdit.");
} else {
// use TextEdit instead
[sws openFile:path withApplication:@"TextEdit"];
}
}