diff --git a/Applications/QuickLookGenerator/src/generate.mm b/Applications/QuickLookGenerator/src/generate.mm index 529c6e71..2d664918 100644 --- a/Applications/QuickLookGenerator/src/generate.mm +++ b/Applications/QuickLookGenerator/src/generate.mm @@ -1,3 +1,4 @@ +#import #import "plugin.h" #import #import @@ -58,7 +59,22 @@ static std::string URLtoString (CFURLRef url) static std::string setup_buffer (CFURLRef url, ng::buffer_t& buffer, size_t maxSize = 20480, size_t maxLines = SIZE_T_MAX) { std::string filePath = URLtoString(url); - std::string fileContents = file::read_utf8(filePath, nullptr, maxSize); + + std::string fileContents = NULL_STR; + if(path::extension(filePath) == ".scpt") + { + @autoreleasepool { + NSDictionary* err = nil; + if(OSAScript* script = [[OSAScript alloc] initWithContentsOfURL:(__bridge NSURL*)url error:&err]) + { + fileContents = [[script source] UTF8String] ?: NULL_STR; + std::replace(fileContents.begin(), fileContents.end(), '\r', '\n'); + } + } + } + + if(fileContents == NULL_STR) + fileContents = file::read_utf8(filePath, nullptr, maxSize); if(maxLines != SIZE_T_MAX) fileContents.erase(std::find_if(fileContents.begin(), fileContents.end(), [&maxLines](char ch) { return ch == '\n' && --maxLines == 0; }), fileContents.end()); diff --git a/Applications/QuickLookGenerator/target b/Applications/QuickLookGenerator/target index 73be01b1..f17d52fd 100644 --- a/Applications/QuickLookGenerator/target +++ b/Applications/QuickLookGenerator/target @@ -1,7 +1,7 @@ TARGET_NAME = TextMateQL SOURCES = src/*.{c,mm} CP_Resources = resources/* -FRAMEWORKS = CoreFoundation QuickLook AppKit +FRAMEWORKS = CoreFoundation QuickLook AppKit OSAKit LINK += layout buffer bundles file cf ns OakAppKit OakFoundation LN_FLAGS -= -Wl,-dead_strip_dylibs