• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Folder lister
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Folder lister


  • Subject: Folder lister
  • From: Shane Stanley <email@hidden>
  • Date: Fri, 04 Dec 2015 17:06:08 +1100

One of the things I regularly want to do is see the contents of a folder, fully expanded, but with full paths. I've written scripts to do it before, but sometimes the full paths are distracting. I finally got around to writing one that shows the paths, but with all but the name in a lighter color. The listing gets saved to the desktop as an rtf file, and opened in the default rtf editor. It's not perhaps the most obvious of code, but some might find it useful.

It requires the BridgePlus script library (download here: <http://www.macosxautomation.com/applescript/apps/BridgePlus.html>), although it could easily be modified to do without it. Because it's potentially doing a lot of styling, don't point it at very large folders and expect to see anything in a hurry.

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:

-- 
Shane Stanley <email@hidden>
<www.macosxautomation.com/applescript/apps/>

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

  • Prev by Date: Re: Smart-File Unsaved Script
  • Next by Date: Re: Folder lister
  • Previous by thread: Re: Smart-File Unsaved Script
  • Next by thread: Re: Folder lister
  • Index(es):
    • Date
    • Thread