Monday, September 28, 2020
  • Index
  •  » Code Exchange
  •  » Choose a folder you like to list directory contents as TextEdit items

#1 2020-01-25 10:00:28 pm

Fredrik71
Member
Registered: 2019-10-23
Posts: 393

Choose a folder you like to list directory contents as TextEdit items

Sometimes we want to list a directory and get content as TextEdit items.
Specially if we build a list of favourite songs or add descriptions that we do not need as metadata.

Applescript:

(*
   Choose a folder you like to list directory contents as TextEdit items.
       Ex. of use.
       ls -1d [0-9]*    <--- List all songs in your folder if pattern start with a number.
                        1-01.Stand.Up.(From.Harriet).flac
       ls -1d [A-Z]* <--- List all folder if pattern start with capital character
*)


on run
   set this_folder to (choose folder with prompt "Choose the folder to list directory contents as TextEdit items:") --> alias
       set thePath to POSIX path of this_folder --> text
   do shell script "cd " & quoted form of (thePath) & "; " & "ls -1d * | open -f -a \"TextEdit\""
end run

Edit: 2020-02-03, Thanks Nigel for your feedback.

Last edited by Fredrik71 (2020-02-03 06:37:37 am)


I could teach you to cook but I couldn't do anything if you do not have desire or commitment for it.

Offline

 

#2 2020-02-02 08:28:46 am

Nigel Garvey
Moderator
From:: Warwickshire, England
Registered: 2002-11-20
Posts: 5284

Re: Choose a folder you like to list directory contents as TextEdit items

Hi Fredrik71.

You don't need the 'tell' statement or either of the coercions. The Finder plays no part in the process. 'POSIX path' is properly a property of an 'alias' and returns a text result anyway.

Applescript:

(*
   Choose a folder you like to list directory contents as TextEdit items.
       Ex. of use.
       ls -1d [0-9]*    <--- List all songs in your folder if pattern start with a number.
                        1-01.Stand.Up.(From.Harriet).flac
       ls -1d [A-Z]* <--- List all folder if pattern start with capital character
*)


on run
   set this_folder to (choose folder with prompt "Choose the folder to list directory contents as TextEdit items:") --> result is an alias
   set thePath to POSIX path of this_folder --> result is text
   do shell script "cd " & quoted form of (thePath) & "; " & "ls -1d * | open -f -a \"TextEdit\""
end run


NG

Offline

 
  • Index
  •  » Code Exchange
  •  » Choose a folder you like to list directory contents as TextEdit items

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)