From a640627fe1ff6c42f1bff8a76b1df2ae4b96f0bc Mon Sep 17 00:00:00 2001 From: Christopher Snowhill Date: Thu, 1 Jun 2023 21:34:16 -0700 Subject: [PATCH] Playlist: Add a workaround for AppleStript URLs AppleScript is apparently such a legacy system, that when it sends URLs to your app to open, they're in the old Carbon format. So we need to translate these to proper URL strings for the rest of the app to deal with them at all. The format of these URLs is as follows: /method/:: Followed optionally by: username/password@ Where the slash and password are optional. Followed by: hostname Followed optionally by: /portnumber And finally, followed by: :path:on:server:filename.ext So, in hostname field, we must swap slashes to colons. And in the path field, swap colons to slashes. What a bizarre world. Signed-off-by: Christopher Snowhill --- Application/AppController.m | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/Application/AppController.m b/Application/AppController.m index 2291287f2..bfa497b1a 100644 --- a/Application/AppController.m +++ b/Application/AppController.m @@ -496,7 +496,37 @@ static AppController *kAppController = nil; NSMutableArray *urls = [NSMutableArray array]; for(NSString *filename in filenames) { - [urls addObject:[NSURL fileURLWithPath:filename]]; + NSURL *url = nil; + if([[NSFileManager defaultManager] fileExistsAtPath:filename]) { + url = [NSURL fileURLWithPath:filename]; + } else { + if([filename hasPrefix:@"/http/::"] || + [filename hasPrefix:@"/https/::"]) { + // Stupid Carbon bodge for AppleScript + NSString *method = nil; + NSString *server = nil; + NSString *path = nil; + + NSScanner *objScanner = [NSScanner scannerWithString:filename]; + + if(![objScanner scanString:@"/" intoString:nil] || + ![objScanner scanUpToString:@"/" intoString:&method] || + ![objScanner scanString:@"/::" intoString:nil] || + ![objScanner scanUpToString:@":" intoString:&server] || + ![objScanner scanString:@":" intoString:nil]) { + continue; + } + [objScanner scanUpToCharactersFromSet:[NSCharacterSet illegalCharacterSet] intoString:&path]; + // Colons in server were converted to shashes, convert back + NSString *convertedServer = [server stringByReplacingOccurrencesOfString:@"/" withString:@":"]; + // Slashes in path were converted to colons, convert back + NSString *convertedPath = [path stringByReplacingOccurrencesOfString:@":" withString:@"/"]; + url = [NSURL URLWithString:[NSString stringWithFormat:@"%@://%@/%@", method, convertedServer, convertedPath]]; + } + } + if(url) { + [urls addObject:url]; + } } NSDictionary *loadEntriesData = @{ @"entries": urls,