Article View: adobe.scripting.indesign
Article #18065Re: First AppleScript (AS) [large script in body]
From: Shane Stanley
Date: Mon, 28 Apr 2003 07:28
Date: Mon, 28 Apr 2003 07:28
68 lines
3212 bytes
3212 bytes
in article BAD2346B.21A%ChrisH@OvationAdvertising.com, Chris Haas wrote:
> I've been a Basic programmer for 12+ years now and have many VB scripts for ID
> but this is my first AppleScript. I was wondering if someone could take a look
> at this script which relinks all images from LoRes to HiRes and tell me how
> bad it is.
>
Looks like you're already pretty comfortable with AS to me.
> I just learned AS this weekend and I can't find the VB equivalent of Replace
> so I just made one.
>
This is the sort of thing text items excel at. Your GetVolumePart handler
(and hence the need for replace) could be done like this:
set oldDelims to AppleScript's text item delimiters
set AppleScript's text item delimiters to {":"}
set theVolume to text item 1 of thePath
set AppleScript's text item delimiters to oldDelims
You can also parse paths further like this:
set oldDelims to AppleScript's text item delimiters
set AppleScript's text item delimiters to {":"}
set filesName to text item -1 of thePath
set filesFolder to (text 1 thru text item -2 of thePath) as text
set AppleScript's text item delimiters to oldDelims
Note the use of -1, to count from the end; you could use that instead of
"length of myOldFilePath" later on.
As long as you don't want case insensitivity, your replace handle4r could be
written as:
on Replace(StringToSearchIn, StringToSearchFor, StringToReplaceWith)
set oldDelims to AppleScript's text item delimiters
set AppleScript's text item delimiters to StringToSearchFor
set StringToSearchIn to text items of StringToSearchIn
set AppleScript's text item delimiters to StringToReplaceWith
set StringToSearchIn to (StringToSearchIn as text)
set AppleScript's text item delimiters to oldDelims
return StringToSearchIn
end Replace
> I think I could ask the finder to tell me the Volume name instead of manually
> parsing it but I'm a function guy.
>
And it's often quicker, especially using text item delimiters.
> tell myLink to update
>
I'm not sure that's necessary.
> set lstAlreadyLinked to lstAlreadyLinked & (name of myLink)
>
Better to use:
set end of lstAlreadyLinked to (name of mylink)
It's more memory efficient and quicker.
> The script seems to work beautifully, btw.
That's the main thing.
Cheers,
--
Shane Stanley, sstanley@myriad-com.com.au
Technical Details
Message-ID:
<BAD3154D.57D7A%sstanley@myriad-com.com.au>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-08!supernews.com!news-out.visi.com!petbe.visi.com!eusc.inter.net!newsfeed01.sul.t-online.de!t-online.de!WebXReferences:
<BAD2346B.21A%ChrisH@OvationAdvertising.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f939a,a14109d39133ad8c X-Google-Attributes: gidf939a,public X-Google-ArrivalTime: 2003-04-28 00:39:43 PST From: Shane Stanley <sstanley@myriad-com.com.au> Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-08!supernews.com!news-out.visi.com!petbe.visi.com!eusc.inter.net!newsfeed01.sul.t-online.de!t-online.de!WebX Newsgroups: adobe.scripting.indesign Subject: Re: First AppleScript (AS) [large script in body] Message-ID: <BAD3154D.57D7A%sstanley@myriad-com.com.au> Date: Mon, 28 Apr 2003 00:28:46 -0700 References: <BAD2346B.21A%ChrisH@OvationAdvertising.com> Lines: 78 User-Agent: Microsoft-Outlook-Express-Macintosh-Edition/5.0.6 MIME-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 8bit