It works on the target of the frontmost Finder window, and if you hold the control key while launching it, it includes the contents of packages.
use AppleScript version "2.3.1"
use scripting additions
use framework "Foundation"
use framework "AppKit"
use script "BridgePlus" version "1.3.1"
set doPackages to not (my checkModifier:"control") -- if control key is down, include contents of packages
tell application "Finder"
try
set theTarget to target of Finder window 1 as alias
on error
error number -128
end try
end tell
set Forder to load framework
-- set up destination path
set deskPath to POSIX path of (path to desktop)
set destURL to (current application's class "NSURL"'s fileURLWithPath:deskPath)'s URLByAppendingPathComponent:"_WindowContents.rtf" -- change to suit
-- set up paragraph style for line-spacing
set parStyle to current application's NSParagraphStyle's defaultParagraphStyle()'s mutableCopy()
parStyle's setLineHeightMultiple:1.3 -- change to suit
-- set up font
set theFont to current application's NSFont's fontWithName:"Menlo-Regular" |size|:14.0 -- change to suit
-- set up colors
set highlightColor to current application's NSDictionary's dictionaryWithObject:(current application's NSColor's blueColor()) forKey:(current application's NSForegroundColorAttributeName) -- change to suit
set lighterColor to current application's NSDictionary's dictionaryWithObject:(current application's NSColor's lightGrayColor()) forKey:(current application's NSForegroundColorAttributeName) -- change to suit
-- define base style from above
set baseStyle to current application's NSMutableDictionary's dictionaryWithObjects:{theFont, parStyle} forKeys:{current application's NSFontAttributeName, current application's NSParagraphStyleAttributeName}
baseStyle's addEntriesFromDictionary:lighterColor
-- get all items in folder
set allPaths to Forder's itemsIn:theTarget recursive:true skipHidden:true skipInsidePackages:doPackages asPaths:true
-- make string of paths
set theString to allPaths's componentsJoinedByString:linefeed
set theString to theString's stringByAppendingString:linefeed
-- get range of last component of paths
set theRegex to current application's NSRegularExpression's regularExpressionWithPattern:"[^\\/]+\\n" options:0 |error|:(missing value)
set theMatches to (theRegex's matchesInString:theString options:0 range:{0, theString's |length|()})'s valueForKey:"range"
-- make styled string
set styledString to current application's NSMutableAttributedString's alloc()'s initWithString:theString attributes:baseStyle
-- add highlightColor to the names
repeat with aRange in theMatches
(styledString's addAttributes:highlightColor range:aRange)
end repeat
-- get RTF data, write it to file, then open the file
set theData to styledString's RTFFromRange:{0, styledString's |length|()} documentAttributes:(missing value)
theData's writeToURL:destURL atomically:true
current application's NSWorkspace's sharedWorkspace()'s openURL:destURL
on checkModifier:keyName
if keyName = "option" then
set theMask to current application's NSAlternateKeyMask as integer
else if keyName = "control" then
set theMask to current application's NSControlKeyMask as integer
else if keyName = "command" then
set theMask to current application's NSCommandKeyMask as integer
else if keyName = "shift" then
set theMask to current application's NSShiftKeyMask as integer
else
return false
end if
set theFlag to current application's NSEvent's modifierFlags() as integer
if ((theFlag div theMask) mod 2) = 0 then
return false
else
return true
end if
end checkModifier: