Re: AppleScript and shell scripting
Re: AppleScript and shell scripting
- Subject: Re: AppleScript and shell scripting
- From: has <email@hidden>
- Date: Thu, 26 Jul 2007 14:11:24 +0100
On 26 Jul 2007, at 12:08, Philip Aker wrote:
If a given solution is cumbersome, that's a strong indication that
you're doing it wrong.
[snip code]
…, 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
Indeed, there are various ways to make the code terser, more
portable, etc, if those things are an issue for you. These are just
implementation/optimisation details though; what's important is using
the right problem-solving technique for the job, which for textual
pattern matching is regular expressions. Ed's problem was that he's
letting his fear/dislike of implementation X (Unix shell) blind him
to the benefits of using technique Y (regular expressions) despite
them being completely orthogonal (i.e. execution vs concept). That in
turn resulted in him promoting an inferior solution that ultimately
undermined his whole argument for using a more AppleScript-centric
approach. My script simply shows that it's possible to use the right
technique while still working within an implementation (AppleScript)
that he's comfortable with.
Personally, I think that anyone who's using AppleScript as their sole
language on a regular basis should make a point of learning at least
one other language (e.g. Python, Ruby, bash, Smalltalk) as soon as
they can get over their initial syntaxophobia. The first step to
becoming a competent scripter in *any* language - AppleScript
included - is to learn how much you *don't* know. Exposing yourself
to other tools and practices outside your current comfort zone will
really help to open your eyes here, and even if you decide not to
continue using that language, the knowledge and experience you've
gained will help to make you a better AppleScripter.
Cheers,
has
--
http://appscript.sourceforge.net
http://rb-appscript.rubyforge.org
http://appscript.sourceforge.net/objc-appscript.html
_______________________________________________
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