• 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: Routine for parsing path-filename....
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Routine for parsing path-filename....


  • Subject: Re: Routine for parsing path-filename....
  • From: Axel Luttgens <email@hidden>
  • Date: Sat, 27 May 2006 12:07:50 +0200

On 27/05/06 11:18, Stefan Eriksson wrote:
Hello !

[...]

Got this far... wont compile stops on the "to switch text..."

[...]

Any ideas,
In your code, you are trying to define handler "switchText" within another handler "parse"; handler imbrication is not allowed by the language.
You just need to move one line:

    set thePath to "PB G4 Ster:Users:ster:Documents:Project:Aktuella projekt:Breweries:East Europe:Baltic:100-150 Zelta Gold.pdf"
    set the_file to "100-150 Zelta Gold.pdf"

    parse(thePath, the_file)

    on parse(thePath, the_file)
        set replaceItWith to ""
        set newText to switchText of thePath from the_file to replaceItWith
    end parse

    to switchText of theText from SearchString to ReplaceString
        set oldDelims to AppleScript's text item delimiters
        set AppleScript's text item delimiters to SearchString
        set newText to text items of theText
        set AppleScript's text item delimiters to ReplaceString
        set newText to newText as text
        set AppleScript's text item delimiters to oldDelims
        return newText
    end switchText

But then, some cleaning opportunities appear more clearly:

    set thePath to "PB G4 Ster:Users:ster:Documents:Project:Aktuella projekt:Breweries:East Europe:Baltic:100-150 Zelta Gold.pdf"
    set the_file to "100-150 Zelta Gold.pdf"

    parse(thePath, the_file)

    on parse(thePath, the_file)
        return switchText of thePath from the_file to ""
    end parse

    to switchText of theText from SearchString to ReplaceString
        local oldDelims
        set oldDelims to AppleScript's text item delimiters
        set AppleScript's text item delimiters to SearchString
        set
theText to text items of theText
        set AppleScript's text item delimiters to ReplaceString
        set
theText to theText as text
        set AppleScript's text item delimiters to oldDelims
        return
theText
    end switchText

maybe there is an easier way to do the parsing thing !?

The global effect of your code seems to just get the path of an enclosing folder.
If that is the goal, then yes, there are easier ways ;-)
Could you tell us a bit more about what you want to achieve?


Axel


 _______________________________________________
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

References: 
 >Routine for parsing path-filename.... (From: Stefan Eriksson <email@hidden>)

  • Prev by Date: Re: iTunes : "File permission error"
  • Next by Date: Re: Routine for parsing path-filename....
  • Previous by thread: Routine for parsing path-filename....
  • Next by thread: Re: Routine for parsing path-filename....
  • Index(es):
    • Date
    • Thread