🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: adobe.scripting.indesign
Article #18066

Re: First AppleScript (AS) [large script in body]

#18066
From: Chris Haas
Date: Mon, 28 Apr 2003 08:03
82 lines
4162 bytes
On 4/28/03 2:28 AM, in article BAD3154D.57D7A%sstanley@myriad-com.com.au,
"Shane Stanley" <sstanley@myriad-com.com.au> wrote:

> 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,
Thanks Shane! I can't believe I used the text delim in one place but not
where you showed me. Makes total sense now! I think if you don't call update
and then try to reference the Link in another script before saving you get
an error. I could be wrong but for some reason in one of my VB scripts I had
to do it so I've just been doing it ever since. Thanks also for the speed
tip. I've got my O'Reilly book next to me but they didn't really delve into
what's the best way to do things. Man, I've been able to pick up most any
language because they all follow similar concepts but AS has been one of the
toughest just because its so simple!

Thanks again Shane!
Technical Details
Message-ID: <BAD24A85.220%ChrisH@OvationAdvertising.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-04!sn-xit-01!sn-xit-08!supernews.com!newsfeed.news2me.com!newsfeed.icl.net!newsfeed.fjserv.net!lnewspeer00.lnd.ops.eu.uu.net!emea.uu.net!newsfeed01.sul.t-online.de!t-online.de!WebX
References: <BAD2346B.21A%ChrisH@OvationAdvertising.com> <BAD3154D.57D7A%sstanley@myriad-com.com.au>

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 01:08:47 PST
From: Chris Haas <ChrisH@OvationAdvertising.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-04!sn-xit-01!sn-xit-08!supernews.com!newsfeed.news2me.com!newsfeed.icl.net!newsfeed.fjserv.net!lnewspeer00.lnd.ops.eu.uu.net!emea.uu.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: <BAD24A85.220%ChrisH@OvationAdvertising.com>
Date: Mon, 28 Apr 2003 01:03:33 -0700
References: <BAD2346B.21A%ChrisH@OvationAdvertising.com> <BAD3154D.57D7A%sstanley@myriad-com.com.au>
Lines: 101
User-Agent: Microsoft-Entourage/10.1.0.2006
MIME-Version: 1.0
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit