• 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
Re: AppleScript and shell scripting
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: AppleScript and shell scripting


  • Subject: Re: AppleScript and shell scripting
  • From: Philip Aker <email@hidden>
  • Date: Thu, 26 Jul 2007 04:08:36 -0700

On 2007-07-25, at 13:26:43, has wrote:

If a given solution is cumbersome, that's a strong indication that you're doing it wrong.

[…]

set myFolder to choose folder

-- Get names of all files in folder:
tell application "Finder"
    set allFileNames to name of every file of myFolder
end tell

-- Filter for matching filenames:
set matchingFileNames to {}
tell application "TextCommands"
    repeat with fileName in allFileNames
        if check fileName matches "l325010[a-z].*" then
            set end of matchingFileNames to fileName
        end if
    end repeat
end tell

-- Get list of Finder references to matching files (if needed):
tell application "Finder"
    set foundFiles to every file of myFolder whose name is in matchingFileNames
end tell

…, the proper thing to do is post a better solution …

Quite right to both of the above. That's why knowledge of the basic shell commands and minimal regexp patterns can distill a solution like the above to something like:

set fold to (choose folder)
set ppath to quoted form of (POSIX path of fold)
set matches to paragraphs of (do shell script "cd " & ppath & ";ls 1325010[a-z]*")
tell application "Finder" to set foundFiles to every file of fold whose name is in matches

to the advantage of the purpose. Note it could have been reduced it to two lines :-).


Philip Aker
email@hidden
 _______________________________________________
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

  • Follow-Ups:
    • Re: AppleScript and shell scripting
      • From: "Gary (Lists)" <email@hidden>
    • Re: AppleScript and shell scripting
      • From: has <email@hidden>
References: 
 >Re: AppleScript and shell scripting (From: has <email@hidden>)

  • Prev by Date: Re: AppleScript-Users Digest, Vol 4, Issue 345
  • Next by Date: Re: AppleScript and shell scripting
  • Previous by thread: Re: AppleScript and shell scripting
  • Next by thread: Re: AppleScript and shell scripting
  • Index(es):
    • Date
    • Thread