I have this script, possibly written by Nigel Garvey, that gets file names from a folder and writes them to a text file. I have used this script for years, and thanks again.
I am trying to modify it so I can write to clipboard. Which I have done.
I would like to make 2 changes to the script and I cannot figure out how to do them.
The first issue is to remove the “Header” line that is added to the file / clipboard. See second commented line, “Just the heading”.
The second issue is to remove the file extensions. I have tried changing all the delimiters. I am not sure where a hide extensions request would go, in the createText function or main?
-- Create the text to be written to the file.
-- Just a heading and the item names, indented according to their positions in the hierarchy.
-- (Uncomment the (* *) comment markers to preserve the full paths.)
on createText(posixPaths)
script o
property paths : posixPaths
end script
set rootPath to beginning of o's paths
set item 1 of o's paths to "Contents of " & rootPath & linefeed
set astid to AppleScript's text item delimiters
-- (*
considering case
set AppleScript's text item delimiters to ""
set tabStr to {tab, tab, tab, tab, tab, tab, tab, tab, tab, tab, tab, tab, tab, tab, tab, tab, tab, tab, tab, tab} as text -- Hopefully more than needed!
set AppleScript's text item delimiters to "/"
set nonIndent to (count rootPath's text items) -- 1
set len to (count posixPaths)
repeat with i from 2 to len
set thisPath to item i of o's paths
set tiCount to (count thisPath's text items)
set thisName to text item -1 of thisPath
-- If the item name contains any colons, restore the original slashes.
if (thisName contains ":") then
set AppleScript's text item delimiters to ":"
set thisName to thisName's text items
set AppleScript's text item delimiters to "/"
set thisName to thisName as text
end if
-- If this is a folder path, append a colon to the name.
if ((i < len) and (item (i + 1) of o's paths begins with thisPath)) then set thisName to thisName & ":" -- or "/", if preferred.
set item i of o's paths to text 1 thru (tiCount - nonIndent) of tabStr & thisName
end repeat
-- *)
set AppleScript's text item delimiters to linefeed
set outText to o's paths as text
-- (*
set AppleScript's text item delimiters to linefeed & tab
set outText to outText's text items
set AppleScript's text item delimiters to linefeed
set outText to outText as text
end considering
-- *)
set AppleScript's text item delimiters to astid -- Set Delimiters Back !!!
return outText
end createText
on main()
set rootFolder to (choose folder with prompt "Choose a folder to catalogue.")
-- List the hierarchy as POSIX paths, omitting any that contain elements beginning with ".".
set thePaths to paragraphs of (do shell script "find -f " & (quoted form of POSIX path of rootFolder) & " \\! -path \"*/.*\"")
set outText to createText(thePaths)
set the clipboard to outText
end main
main()
Thanks,
Randy