• 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: RegExps in AS
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: RegExps in AS


  • Subject: Re: RegExps in AS
  • From: kai <email@hidden>
  • Date: Thu, 24 Feb 2005 03:07:47 +0000


On Wed, 23 Feb 2005 09:41:03 -0500, John Stewart <email@hidden> wrote:


On 2/22/05 at 11:34 PM,  the entity kai spoke thusly

On Monday, February 21, 2005, at 10:25  pm, Ihar 'Philips' Filipau
wrote:


On 20 Feb 2005, at 22:02, kai wrote:

One way might be to use AppleScript's text item delimiters:


Or one could do it with nothing but the Finder which doesn't need RegEx or TIDs.

I agree:

http://lists.apple.com/archives/applescript-users/2005/Feb/msg00694.html

This isn't going to set any speed records but it is accurate. It's also easily changed to filter extensions by adding a 'whose' clause.

    --> Cut <--
    tell application "Finder"
        set flist to every file of (choose folder) as alias list
        repeat with aFile in flist
            set temp to contents of aFile
            set oldExt to extension hidden of temp
            set extension hidden of temp to true
            set fname to displayed name of temp
            set extension hidden of temp to false
            set name of temp to fname
            set extension hidden of temp to oldExt
        end repeat
    end tell
    --> Cut <--

That appears to return a Boolean value, rather than a list of names.

More importantly, I'm afraid that I have to advise folks not to try running this script as it stands - since it will permanently strip extensions from *all* files in a folder (even those with previously hidden extensions). Test it on a folder containing numerous files with various extensions, and you could end up with quite a bit of repair work on your hands. (The offending line: 'set name of temp to fname'.)

Also, don't forget that if you're going to use the Finder's 'as alias list' command, you'll need to trap it for the possibility of a folder that contains only one item.

The following suggestion aims to sidestep these potential problems and to restore individual extensions - but without resorting to a repeat loop (making it significantly faster):

-------------------------

tell application "Finder" to tell folder (choose folder)
	tell (files whose extension hidden is false)
		set n to name
		set extension hidden to true
	end tell
	set l to displayed name of files
	set extension hidden of files whose name is in n to false
end tell
l

-------------------------

---
kai

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: RegExps in AS
      • From: kai <email@hidden>
  • Prev by Date: Re: Creating a folder in user preferences
  • Next by Date: Re: Creating a folder in user preferences
  • Previous by thread: Re: RegExps in AS
  • Next by thread: Re: RegExps in AS
  • Index(es):
    • Date
    • Thread