• 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: has <email@hidden>
  • Date: Wed, 25 Jul 2007 21:26:43 +0100

Ed Stockly wrote:

Now AppleScript is getting lost in the Shell Scripting flood on the AppleScript Users list. And because of that we're losing the AppleScript target market.

If you're really worried by this, how about starting a concerted effort to develop a collection of libraries/osaxen/scriptable FBAs that provides this target market with the functionality it needs? Because until such time as users can get that functionality natively, they're going to keep going elsewhere to get it.



Non-programmers drawn by an easy to understand programming language come here and are bombarded with what I consider to be among the most incomprehensible of computer languages, when they should be getting the most easily understood computer language.

Whatever the faults of Unix shell languages, the notion that AppleScript is "the most easily understood computer language" is absolute bunkum. What experience, if any, do you have with languages other than AppleScript? I'm not entirely unsympathetic to the 'lean towards AppleScript where practical' argument, but I'm wondering if your own position isn't motivated at least in part by a phobia of tools and techniques you don't understand yourself.



All I'm asking (and I certainly hope I haven't been rude, I know I've been
persistent and stubborn, but not rude) is that detailed discussions about
shell scripting be referred to the Mac Scripter digest.

You mean the MACSCRPT mailing list.


There's not much traffic on that list, and, most of threads are AppleScript
anyway.

The trouble with MACSCRPT is that it's slowly fallen out of favour since the move to OS X: questions on AppleScript are better posted here or at MacScripter.net, while questions on anything else get taken to more dedicated forums.



(AppleScript is, by the way, the most commonly used scripting
language on the platform).

Do you have stats for this? I did a quick search but didn't manage to find any platform-specific figures. Pre-OS X I've no doubt this was true, but nowadays I dunno. Tiobe puts Perl, Python and Ruby at 5th, 6th, 8th and 10th (5.3, 3.0, 2.1%) respectively while AppleScript isn't even in the top 50 (<0.08%).



What's the harm in responding to a user with something like this:

"An appleScript solution might be a bit cumbersome for what you're trying to do.

If a given solution is cumbersome, that's a strong indication that you're doing it wrong. The whole point of scripting is to make users' lives easier, not harder, so giving them an ideologically motivated solution that's rubbish to understand/use isn't doing them, you or anyone else any favours.


Let's go back to your original solution:


set myFolder to choose folder
tell application "Finder"
set fileList to {"l325010a", "l325010b", "l325010c", "l325010d", "l325010e"}
set allFoundFiles to {}
repeat with thisFileName in fileList
try
set foundFiles to (every file of myFolder whose name begins with thisFileName)
if the class of foundFiles is not list then
set the end of allFoundFiles to foundFiles
else
set allFoundFiles to allFoundFiles & foundFiles
end if
end try
end repeat
return allFoundFiles
end tell



The first problem with this is that it doesn't actually do what the user requested, which was to match names beginning "l32501" followed by any character from "a" to "z", with subsequent attempts to rectify this mistake turning into a silly make-work exercise. Which leads us to the second problem, because as soon as somebody says they want to do pattern matching in text, there is only one [1] sensible answer: use regular expressions. It's a solved problem, and the solution is a widespread, mature and well-understood one. Reinventing this particular wheel, and badly at that, is just leading novice users down the garden path - something that doesn't reflect well on yourself, the community or AppleScript itself.


Thus, the "right" AppleScript solution (using your preferred choice of regular expression tool) should be something like:


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



So if you don't like the solutions that other folks are posting, the proper thing to do is post a better solution yourself, not an inferior one followed by complaints about everyone else's lack of devotion to the One True Language. Remember, it's only a tool, not a religion.


Regards,

has

[1] Unless the task is sufficiently complex that a full-blown parser is required; but that's not somewhere the typical AppleScripter will ever need to go so we can ignore it for sake of argument.
--
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
  • Follow-Ups:
    • Re: AppleScript and shell scripting
      • From: Philip Aker <email@hidden>
    • Re: AppleScript and shell scripting
      • From: "John C. Welch" <email@hidden>
    • Re: AppleScript and shell scripting
      • From: "Mark J. Reed" <email@hidden>
  • Prev by Date: Re: Strange char "?" in html source from Safari
  • 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